Skip to content

Commit 6e33ac0

Browse files
committed
with mypy
1 parent 65ce1a6 commit 6e33ac0

File tree

9 files changed

+177
-64
lines changed

9 files changed

+177
-64
lines changed

.github/workflows/run-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ jobs:
3030
pip install -U pytest codecov pytest-cov
3131
pip install .
3232
33-
# - name: Type checking
34-
# run: |
35-
# mypy pyModeS tests
33+
- name: Type checking
34+
run: |
35+
mypy pyModeS
3636
3737
- name: Run tests (without Cython)
3838
run: |

pyModeS/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from . import c_common as common
66
from .c_common import *
77
except:
8-
from . import py_common as common
9-
from .py_common import *
8+
from . import py_common as common # type: ignore
9+
from .py_common import * # type: ignore
1010

1111
from .decoder import tell
1212
from .decoder import adsb

pyModeS/c_common.pyi

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def hex2bin(hexstr: str) -> str: ...
2+
def bin2int(binstr: str) -> int: ...
3+
def hex2int(hexstr: str) -> int: ...
4+
def bin2hex(binstr: str) -> str: ...
5+
6+
7+
def df(msg: str) -> int: ...
8+
def crc(msg: str, encode: bool = False) -> int: ...
9+
10+
11+
def floor(x: float) -> float: ...
12+
def icao(msg: str) -> str: ...
13+
def is_icao_assigned(icao: str) -> bool: ...
14+
15+
16+
def typecode(msg: str) -> int: ...
17+
def cprNL(lat: float) -> int: ...
18+
19+
20+
def idcode(msg: str) -> str: ...
21+
def squawk(binstr: str) -> str: ...
22+
23+
24+
def altcode(msg: str) -> int: ...
25+
def altitude(binstr: str) -> int: ...
26+
27+
28+
def data(msg: str) -> str: ...
29+
def allzeros(msg: str) -> bool: ...

pyModeS/decoder/__init__.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ def _print(label, value, unit=None):
7171
_print("CPR Longitude", cprlon)
7272
_print("Altitude", alt, "feet")
7373

74-
if tc == 29: # target state and status
74+
if tc == 29: # target state and status
7575
_print("Type", "Target State and Status")
7676
subtype = common.bin2int((common.hex2bin(msg)[32:])[5:7])
7777
_print("Subtype", subtype)
7878
tcas_operational = adsb.tcas_operational(msg)
79-
types = {0: "Not Engaged", 1: "Engaged"}
79+
types_29 = {0: "Not Engaged", 1: "Engaged"}
8080
tcas_operational_types = {0: "Not Operational", 1: "Operational"}
8181
if subtype == 0:
8282
emergency_types = {
@@ -87,11 +87,11 @@ def _print(label, value, unit=None):
8787
4: "No communications",
8888
5: "Unlawful interference",
8989
6: "Downed aircraft",
90-
7: "Reserved"
90+
7: "Reserved",
9191
}
9292
vertical_horizontal_types = {
9393
1: "Acquiring mode",
94-
2: "Capturing/Maintaining mode"
94+
2: "Capturing/Maintaining mode",
9595
}
9696
tcas_ra_types = {0: "Not active", 1: "Active"}
9797
alt, alt_source, alt_ref = adsb.target_altitude(msg)
@@ -108,7 +108,12 @@ def _print(label, value, unit=None):
108108
_print("Angle Source", angle_source)
109109
_print("Vertical mode", vertical_horizontal_types[vertical_mode])
110110
_print("Horizontal mode", vertical_horizontal_types[horizontal_mode])
111-
_print("TCAS/ACAS", tcas_operational_types[tcas_operational])
111+
_print(
112+
"TCAS/ACAS",
113+
tcas_operational_types[tcas_operational]
114+
if tcas_operational
115+
else None,
116+
)
112117
_print("TCAS/ACAS RA", tcas_ra_types[tcas_ra])
113118
_print("Emergency status", emergency_types[emergency_status])
114119
else:
@@ -124,14 +129,20 @@ def _print(label, value, unit=None):
124129
_print("Altitude source", alt_source)
125130
_print("Barometric pressure setting", baro, "millibars")
126131
_print("Selected Heading", hdg, "°")
127-
if not(common.bin2int((common.hex2bin(msg)[32:])[46]) == 0):
128-
_print("Autopilot", types[autopilot])
129-
_print("VNAV mode", types[vnav])
130-
_print("Altitude hold mode", types[alt_hold])
131-
_print("Approach mode", types[app])
132-
_print("TCAS/ACAS", tcas_operational_types[tcas_operational])
133-
_print("LNAV mode", types[lnav])
134-
132+
if not (common.bin2int((common.hex2bin(msg)[32:])[46]) == 0):
133+
_print("Autopilot", types_29[autopilot] if autopilot else None)
134+
_print("VNAV mode", types_29[vnav] if vnav else None)
135+
_print(
136+
"Altitude hold mode", types_29[alt_hold] if alt_hold else None
137+
)
138+
_print("Approach mode", types_29[app] if app else None)
139+
_print(
140+
"TCAS/ACAS",
141+
tcas_operational_types[tcas_operational]
142+
if tcas_operational
143+
else None,
144+
)
145+
_print("LNAV mode", types_29[lnav] if lnav else None)
135146

136147
if df == 20:
137148
_print("Protocol", "Mode-S Comm-B altitude reply")

pyModeS/decoder/adsb.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# noqa
2-
31
"""ADS-B module.
42
53
The ADS-B module also imports functions from the following modules:

0 commit comments

Comments
 (0)