fix(types): resolve mypy 3.10 errors#1921
Conversation
Replace Python 3.11+ only constructs (StrEnum, typing.Self) with 3.10-compatible equivalents, and clear up Any-leak / type-ignore gaps surfaced by strict mypy.
Greptile SummaryThis PR fixes 14 mypy errors that were failing CI under Confidence Score: 5/5Safe to merge — all changes are pure type-annotation fixes with no runtime behavior changes. Every substantive change either swaps a 3.11+ typing feature for a 3.10-compatible equivalent, adds a typed local to help mypy infer a known-correct type, or widens an existing
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Python version check\n(sys.version_info)"] -->|">= 3.11"| B["from typing import Self"]
A -->|"< 3.11"| C["from typing_extensions import Self"]
B --> D["imageDetections.py\nImageDetections.filter() -> Self"]
C --> D
D --> E["module2D.py\nfiltered: ImageDetections2D = .filter(...)"]
F["StrEnum (3.11+)"] -->|replaced with| G["(str, Enum) mixin\nelements.py / plot.py"]
H["NDArray[np.float64] | None"] -->|"result: NDArray[np.float64] = arr[:n].copy()"| I["mujoco_shm.py\ntyped local eliminates Any leak"]
J["memoryview(np.ascontiguousarray(...))"] -->|"# type: ignore[arg-type]"| K["Image.py\nnumpy buffer protocol not typed as Buffer"]
L["super().__getstate__()"] -->|"# type: ignore[misc, assignment]"| M["pubsubrpc.py\nhasattr-guarded call"]
Reviews (5): Last reviewed commit: "fix(types): annotate **kwargs and Observ..." | Re-trigger Greptile |
CI was installing cuda extras while local runs skip them on non-GPU machines, so mypy saw a different package set in CI than developers see locally. Pin both to the same flags so failures surface identically.
This reverts commit bbc86e7.
CI mypy (no --python-version flag, MYPYPATH=ROS humble) reported errors on lines that were already covered by # type: ignore in the local 3.10/3.12 runs. Replace the misplaced ignores with real annotations: - openai.py:query: split signature, add `**kwargs: Any` and `dict[str, Any]` for response_format - moondream_hosted.py:query_detections: `**kwargs: Any` - video_query.py:get_bbox_from_qwen: move type-arg ignore onto the actual Observable line Also silence ruff N812 for the conventional `import torch.nn.functional as F`.
Description
CI was failing with 14 mypy errors under
--python-version 3.10. This PR resolves all of them without changing runtime behavior.memory2/vis/plot/{elements,plot}.py— replacedenum.StrEnum(3.11+) with the existing-in-codebase(str, Enum)mixin pattern (matchesVoice,Go2Mode).perception/detection/type/imageDetections.py— replacedtyping.Self(3.11+) with the version-guarded import pattern already used incore/resource.py.simulation/engines/mujoco_shm.py— bound.copy()results to typed locals so theNDArray[np.float64]return type isn't anAnyleak.protocol/rpc/pubsubrpc.py— extended the existingtype: ignore[assignment]to[misc, assignment]to cover thehasattr-guardedsuper().__getstate__()call.msgs/sensor_msgs/Image.py— added# type: ignore[arg-type]onmemoryview(np.ascontiguousarray(...))(numpy implements the buffer protocol but isn't typed asBuffer).perception/detection/module2D.py— boundimageDetections.filter(...)to a typed local to drop theSelf→Anyleak.How to Test
Run mypy on both supported Python versions:
Expect: clean on both.
Contributor License Agreement
Closes DIM-XXX