diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 347216f2fb..1eb5f632b9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,18 +24,14 @@ repos: # if you've got a short variable name that's getting flagged, add it here - -L bu,ro,te,ue,alo,hda,ois,nam,nams,ned,som,parm,setts,inout,warmup - --builtins clear,rare,informal,usage,code,names,en-GB_to_en-US -- repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.931 +- repo: local hooks: - id: mypy - exclude: '^(pyextra/)|(cereal/)|(rednose/)|(panda/)|(laika/)|(opendbc/)|(laika_repo/)|(rednose_repo/)/|(tinygrad/)|(tinygrad_repo/)' - additional_dependencies: ['types-PyYAML', 'lxml', 'numpy', 'types-atomicwrites', 'types-pycurl', 'types-requests', 'types-certifi'] - args: - - --warn-redundant-casts - - --warn-return-any - - --warn-unreachable - - --warn-unused-ignores - #- --html-report=/home/batman/openpilot + name: mypy + entry: mypy + language: system + types: [python] + exclude: '^(pyextra/)|(cereal/)|(panda/)|(laika/)|(laika_repo/)|(rednose/)|(rednose_repo/)|(tinygrad/)|(tinygrad_repo/)' - repo: https://github.com/PyCQA/flake8 rev: 4.0.1 hooks: diff --git a/Pipfile b/Pipfile index 3dba2755ab..0d37a136aa 100644 --- a/Pipfile +++ b/Pipfile @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5fea746328dc90e4e1542a334508feda0616b2d19d7904f33a3ecfff2b1a6f79 -size 1621 +oid sha256:67078d38037d44571e909dee2288c4fe9f7a1cc3691fe3165c1628ff3d19cde6 +size 1736 diff --git a/Pipfile.lock b/Pipfile.lock index 928af97ea9..4db1a8b5e5 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7d093d32dfcaf18972f9c62a0b87dc470ee0d74304ca8d659fc142ee0176b7c5 -size 188750 +oid sha256:848091d4b13abe8c0c97c997fc8641953e1685582560a45841bac625eb0991b4 +size 205318 diff --git a/common/realtime.py b/common/realtime.py index 8a79d8d39f..7dd2eb98a6 100644 --- a/common/realtime.py +++ b/common/realtime.py @@ -31,7 +31,7 @@ class Priority: def set_realtime_priority(level: int) -> None: if not PC: - os.sched_setscheduler(0, os.SCHED_FIFO, os.sched_param(level)) # type: ignore[attr-defined] # pylint: disable=no-member + os.sched_setscheduler(0, os.SCHED_FIFO, os.sched_param(level)) # pylint: disable=no-member def set_core_affinity(cores: List[int]) -> None: diff --git a/mypy.ini b/mypy.ini index e2da60f926..39b1b007a7 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,4 +1,16 @@ [mypy] python_version = 3.8 -ignore_missing_imports = True plugins = numpy.typing.mypy_plugin +files = body, common, docs, scripts, selfdrive, site_scons, system, tools +exclude = ^(pyextra/)|(cereal/)|(opendbc/)|(panda/)|(laika/)|(laika_repo/)|(rednose/)|(rednose_repo/)|(tinygrad/)|(tinygrad_repo/)|(xx/) + +; 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 diff --git a/selfdrive/debug/check_freq.py b/selfdrive/debug/check_freq.py index b6f3c91bd0..6436abb4f1 100755 --- a/selfdrive/debug/check_freq.py +++ b/selfdrive/debug/check_freq.py @@ -2,7 +2,7 @@ import argparse import numpy as np from collections import defaultdict, deque -from typing import DefaultDict, Deque +from typing import DefaultDict, Deque, MutableSequence from common.realtime import sec_since_boot import cereal.messaging as messaging @@ -19,7 +19,7 @@ if __name__ == "__main__": socket_names = args.socket sockets = {} - rcv_times: DefaultDict[str, Deque[float]] = defaultdict(lambda: deque(maxlen=100)) + rcv_times: DefaultDict[str, MutableSequence[float]] = defaultdict(lambda: deque(maxlen=100)) valids: DefaultDict[str, Deque[bool]] = defaultdict(lambda: deque(maxlen=100)) t = sec_since_boot() diff --git a/selfdrive/debug/check_timings.py b/selfdrive/debug/check_timings.py index 69304f97b5..083e084ca7 100755 --- a/selfdrive/debug/check_timings.py +++ b/selfdrive/debug/check_timings.py @@ -3,13 +3,13 @@ import sys import time import numpy as np -from typing import DefaultDict, Deque +from typing import DefaultDict, MutableSequence from collections import defaultdict, deque import cereal.messaging as messaging socks = {s: messaging.sub_sock(s, conflate=False) for s in sys.argv[1:]} -ts: DefaultDict[str, Deque[float]] = defaultdict(lambda: deque(maxlen=100)) +ts: DefaultDict[str, MutableSequence[float]] = defaultdict(lambda: deque(maxlen=100)) if __name__ == "__main__": while True: diff --git a/system/hardware/tici/casync.py b/system/hardware/tici/casync.py index 8ae42fa714..993336616d 100755 --- a/system/hardware/tici/casync.py +++ b/system/hardware/tici/casync.py @@ -86,6 +86,7 @@ class RemoteChunkReader(ChunkReader): def parse_caibx(caibx_path: str) -> List[Chunk]: """Parses the chunks from a caibx file. Can handle both local and remote files. Returns a list of chunks with hash, offset and length""" + caibx: io.BufferedIOBase if os.path.isfile(caibx_path): caibx = open(caibx_path, 'rb') else: