Skip to content

Fix trivial mypy errors#647

Open
bizfsc wants to merge 1 commit intocanopen-python:masterfrom
bizfsc:fix/mypy-trivial-fixes
Open

Fix trivial mypy errors#647
bizfsc wants to merge 1 commit intocanopen-python:masterfrom
bizfsc:fix/mypy-trivial-fixes

Conversation

@bizfsc
Copy link
Copy Markdown
Contributor

@bizfsc bizfsc commented Apr 29, 2026

Fix trivial mypy errors to prepare for type checking adoption.

Changes

pyproject.toml

  • Add [[tool.mypy.overrides]] to ignore missing imports for can and canmatrix (third-party libraries without type stubs).

canopen/objectdictionary/__init__.py

  • Replace List[int] with list[int] (PEP 585, supported since Python 3.9).
  • Add type annotations for subindices and names dicts in ODRecord and ODArray.

canopen/lss.py

  • Annotate self.responses as queue.Queue[bytes].

canopen/node/local.py

  • Annotate _read_callbacks and _write_callbacks as list[Callable].

canopen/node/remote.py

  • Annotate sdo_channels as list[SdoClient].

Impact

Reduces mypy errors from 95 to 87 (eliminates all import-not-found, name-defined, and var-annotated errors).

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@acolomb
Copy link
Copy Markdown
Member

acolomb commented Apr 29, 2026

Do the two libraries really not ship any typing info? At least for python-can, I'm certain they do have them, but not as stubs.

Oh, and please, could we try to separate a bit more, touching only related modules at a time?

@bizfsc
Copy link
Copy Markdown
Contributor Author

bizfsc commented Apr 29, 2026

Oh, and please, could we try to separate a bit more, touching only related modules at a time?

I though about this, but I decided against it, because I really tried only to fix the most trivial cases in this PR. There will be future PRs (currently working on it) which will be separated by mypy topic.
Per module PRs are not applicable here, then we would have Count of PR = topic * module. Putting together different topics but for one module in a single PR also seems bad.
The structure of the changes in this PR are coherent and straight forward to review, don't you think?

@acolomb
Copy link
Copy Markdown
Member

acolomb commented Apr 29, 2026

Alright, it is in fact fairly straightforward. One more thing I'd stuff in there though is annotating the argument of add_read_callback() and add_write_callback(), since their only purpose is writing to the newly types lists.

What about the dependency typing info? canmatrix has it in the development branch, but not yet released. can is properly typed and marked as such.

Comment thread pyproject.toml
- Add mypy overrides to ignore missing imports for 'can' and 'canmatrix'
- Replace List[int] with list[int] (PEP 585, supported since Python 3.9)
- Add type annotations for untyped variables (var-annotated):
  - lss.py: Queue[bytes]
  - node/local.py: list[Callable] for callbacks
  - node/remote.py: list[SdoClient] for sdo_channels
  - objectdictionary/__init__.py: dict[int, ODVariable] / dict[str, ODVariable]
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.

2 participants