Skip to content

fix(types): resolve mypy 3.10 errors#1921

Merged
jeff-hykin merged 8 commits intodevfrom
jeff/fix/dev
Apr 27, 2026
Merged

fix(types): resolve mypy 3.10 errors#1921
jeff-hykin merged 8 commits intodevfrom
jeff/fix/dev

Conversation

@jeff-hykin
Copy link
Copy Markdown
Member

@jeff-hykin jeff-hykin commented Apr 27, 2026

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 — replaced enum.StrEnum (3.11+) with the existing-in-codebase (str, Enum) mixin pattern (matches Voice, Go2Mode).
  • perception/detection/type/imageDetections.py — replaced typing.Self (3.11+) with the version-guarded import pattern already used in core/resource.py.
  • simulation/engines/mujoco_shm.py — bound .copy() results to typed locals so the NDArray[np.float64] return type isn't an Any leak.
  • protocol/rpc/pubsubrpc.py — extended the existing type: ignore[assignment] to [misc, assignment] to cover the hasattr-guarded super().__getstate__() call.
  • msgs/sensor_msgs/Image.py — added # type: ignore[arg-type] on memoryview(np.ascontiguousarray(...)) (numpy implements the buffer protocol but isn't typed as Buffer).
  • perception/detection/module2D.py — bound imageDetections.filter(...) to a typed local to drop the SelfAny leak.

How to Test

Run mypy on both supported Python versions:

uv sync --frozen --all-extras --no-extra dds --no-extra cuda
uv run mypy --python-version 3.10 dimos
uv run mypy --python-version 3.12 dimos

Expect: clean on both.

Contributor License Agreement

  • I have read and approved the CLA.

Closes DIM-XXX

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-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

This PR fixes 14 mypy errors that were failing CI under --python-version 3.10. The changes are purely type-correctness fixes with no runtime behavior changes: replacing StrEnum (3.11+) with (str, Enum), guarding Self imports behind a sys.version_info check with a typing_extensions fallback, adding typed locals to help mypy infer NDArray[np.float64], and extending existing type: ignore suppression comments. A number of unrelated files also received Apache license headers and minor formatting cleanups (blank lines, indentation) as part of this pass.

Confidence Score: 5/5

Safe 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 type: ignore comment. No logic paths were altered. The only concern is a P2 pre-commit housekeeping issue around agents_deprecated/ files missing license headers, which won't affect runtime or CI mypy checks.

.pre-commit-config.yaml — verify that removing the global deprecated exclude doesn't cause the insert-license hook to fail on the next commit touching dimos/agents_deprecated/ files.

Important Files Changed

Filename Overview
dimos/perception/detection/type/imageDetections.py Replaced direct from typing import Self with a sys.version_info >= (3, 11) guard that falls back to typing_extensions.Self; typing_extensions>=4.0 is declared in pyproject.toml so the import is safe on Python 3.10.
dimos/memory2/vis/plot/elements.py Replaced StrEnum (3.11+) with (str, Enum) mixin — functionally identical and compatible with Python 3.10.
dimos/memory2/vis/plot/plot.py Same StrEnum(str, Enum) fix as elements.py; no issues.
dimos/simulation/engines/mujoco_shm.py Bound .copy() results to result: NDArray[np.float64] locals to eliminate Any type leak in read_position_command and read_velocity_command; no runtime change.
dimos/protocol/rpc/pubsubrpc.py Extended type: ignore[assignment] to type: ignore[misc, assignment] on the hasattr-guarded super().__getstate__() call to silence mypy's misc error on Python 3.10.
dimos/msgs/sensor_msgs/Image.py Added # type: ignore[arg-type] on memoryview(np.ascontiguousarray(...)) because numpy arrays implement the buffer protocol at runtime but are not typed as Buffer in numpy stubs.
dimos/perception/detection/module2D.py Bound imageDetections.filter(...) result to an ImageDetections2D typed local to drop the SelfAny leak introduced when Self is imported from typing_extensions.
.pre-commit-config.yaml Removed global `exclude: (dimos/models/.*)

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"]
Loading

Reviews (5): Last reviewed commit: "fix(types): annotate **kwargs and Observ..." | Re-trigger Greptile

@jeff-hykin jeff-hykin changed the title fix(types): resolve mypy 3.10 strict errors fix(types): resolve mypy 3.10 errors Apr 27, 2026
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.
@jeff-hykin jeff-hykin enabled auto-merge (squash) April 27, 2026 19:09
mustafab0
mustafab0 previously approved these changes Apr 27, 2026
Copy link
Copy Markdown
Contributor

@mustafab0 mustafab0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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`.
@jeff-hykin jeff-hykin merged commit d1af9c8 into dev Apr 27, 2026
4 checks passed
@jeff-hykin jeff-hykin deleted the jeff/fix/dev branch April 27, 2026 20:08
mustafab0 pushed a commit that referenced this pull request Apr 29, 2026
mustafab0 pushed a commit that referenced this pull request Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants