Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ to ensure that the behavior remains unchanged.
The above tests are themselves tested by:
* a [mutation test](tests/misra/test_mutation.py) on the MISRA coverage

In addition, we run the [ruff linter](https://github.com/astral-sh/ruff) and [mypy](https://mypy-lang.org/) on panda's Python library.
In addition, we run the [ruff linter](https://github.com/astral-sh/ruff) and [ty](https://github.com/astral-sh/ty) on panda's Python library.

## Usage

Expand Down
2 changes: 1 addition & 1 deletion board/jungle/scripts/echo_loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_loopback():
#################################################################
############################# MAIN ##############################
#################################################################
jungle = None
jungle: PandaJungle
counter = 0

if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions board/jungle/scripts/loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def test_loopback():
#################################################################
############################# MAIN ##############################
#################################################################
jungle = None
pandas = [] # type: ignore
jungle: PandaJungle
pandas: list[Panda] = []
panda_serials = []
counter = 0

Expand Down
2 changes: 2 additions & 0 deletions examples/can_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def load(self, filename):
with open(filename) as inp:
reader = csv.reader(inp)
header = next(reader, None)
if header is None:
return
if header[0] == 'time':
self.cabana(reader)
else:
Expand Down
19 changes: 6 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ dev = [
"pytest-timeout",
"pytest-randomly",
"ruff",
"mypy",
"setuptools",
"spidev; platform_system == 'Linux'",
]
Expand All @@ -42,18 +41,6 @@ packages = ["panda"]
[tool.setuptools.package-dir]
panda = "."

[tool.mypy]
# third-party packages
ignore_missing_imports = true

# helpful warnings
warn_redundant_casts = true
warn_unreachable = true
warn_unused_ignores = true

# restrict dynamic typing
warn_return_any = true

# https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml
[tool.ruff]
line-length = 160
Expand All @@ -67,6 +54,12 @@ flake8-implicit-str-concat.allow-multiline=false
[tool.ruff.lint.flake8-tidy-imports.banned-api]
"pytest.main".msg = "pytest.main requires special handling that is easy to mess up!"

[tool.ty.rules]
# Third-party packages (usb1, opendbc, spidev, etc.) can't be resolved by ty
unresolved-import = "ignore"
# Handle is temporarily set to None during reconnection before being reassigned
invalid-assignment = "ignore"

[tool.pytest.ini_options]
addopts = "-Werror --strict-config --strict-markers --durations=10 --ignore-glob='*.sh' --ignore=tests/misra --ignore=tests/som --ignore=tests/hitl"
python_files = "test_*.py"
Expand Down
4 changes: 2 additions & 2 deletions scripts/test_canfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def panda_init(serial, enable_canfd=False, enable_non_iso=False):
p.set_safety_mode(CarParams.SafetyModel.allOutput)
return p

def test_canfd_throughput(p, p_recv=None):
def test_canfd_throughput(p: Panda, p_recv: Panda | None = None):
two_pandas = p_recv is not None
p.set_safety_mode(CarParams.SafetyModel.allOutput)
if two_pandas:
if p_recv is not None:
p_recv.set_safety_mode(CarParams.SafetyModel.allOutput)
# enable output mode
else:
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ source ./setup.sh
scons -j8

# *** lint ***
ty check .
ruff check .
mypy python/


# *** test ***
Expand Down
6 changes: 5 additions & 1 deletion tests/libs/resetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

class Resetter():
def __init__(self):
self._handle = None
self._handle: usb1.USBDeviceHandle | None = None
self._context: usb1.USBContext
self.connect()

def __enter__(self):
Expand All @@ -14,6 +15,7 @@ def __exit__(self, *args):
self.close()

def close(self):
assert self._handle is not None
self._handle.close()
self._context.close()
self._handle = None
Expand All @@ -37,9 +39,11 @@ def connect(self):
assert self._handle

def enable_power(self, port, enabled):
assert self._handle is not None
self._handle.controlWrite((usb1.ENDPOINT_OUT | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE), 0xff, port, enabled, b'')

def enable_boot(self, enabled):
assert self._handle is not None
self._handle.controlWrite((usb1.ENDPOINT_OUT | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE), 0xff, 0, enabled, b'')

def cycle_power(self, dfu=False, ports=None):
Expand Down
Loading