Skip to content

Fix arg-type, return-value, and assignment mypy errors#651

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

Fix arg-type, return-value, and assignment mypy errors#651
bizfsc wants to merge 1 commit intocanopen-python:masterfrom
bizfsc:fix/mypy-type-fixes

Conversation

@bizfsc
Copy link
Copy Markdown
Contributor

@bizfsc bizfsc commented Apr 29, 2026

Fix arg-type, return-value, assignment, return, index, and operator mypy errors across the codebase.

Changes

canopen/nmt.py

  • Use bytes() instead of list[int] for send_message() and send_periodic() calls.
  • Use b'' instead of None for node guarding remote frame data.

canopen/emcy.py

  • Fix wait() return type: Optional[EmcyError] (was EmcyError, but returns None on timeout).

canopen/network.py

  • Fix add_node() return type to Union[RemoteNode, LocalNode] (accepts both).
  • Fix create_node() parameter type to Union[int, LocalNode].
  • Add assert node.id is not None for index safety.
  • Add type: ignore[arg-type] for node construction where OD may be None.

canopen/variable.py

  • Add raise ValueError at end of read() to satisfy missing return.
  • Annotate Bits.raw with proper type.
  • Add isinstance check for value_descriptions dict access.
  • Add type: ignore for dynamically typed operations (decode_phys, decode_desc, encode_bits).

canopen/sdo/base.py

  • Add explicit return None in get_variable().
  • Add type: ignore[return-value] for SdoArray.__len__().

canopen/objectdictionary/__init__.py

  • Fix __getitem__ dot-notation access with isinstance check for indexability.
  • Add explicit return None in get_variable().
  • Annotate ODVariable.parent and ODArray.parent with proper Union types.
  • Fix decode_phys() return type to Union[int, float].
  • Rewrite encode_phys() without intermediate division.
  • Add type: ignore for encode_raw string operations and min/max comparisons.
  • Add type: ignore for dest.close() and source.name in file handling.

Impact

Reduces mypy error count from 95 to 51 (standalone), and combined with PRs #647, #649, #650 will bring the count down significantly further.",
false

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 88.57143% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
canopen/objectdictionary/__init__.py 88.88% 1 Missing and 1 partial ⚠️
canopen/variable.py 75.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

- nmt.py: Use bytes() instead of list[int] for send_message/send_periodic
- emcy.py: Fix wait() return type to Optional[EmcyError]
- network.py: Fix add_node/create_node return types and type narrowing
- variable.py: Fix missing return in read(), annotate Bits.raw, add
  type: ignore for inherently dynamic type operations
- sdo/base.py: Fix missing return in get_variable(), add type: ignore
  for SdoArray.__len__
- objectdictionary/__init__.py: Fix __getitem__ indexability, add
  missing return in get_variable(), annotate ODVariable.parent,
  fix decode_phys/encode_phys types, add type: ignore for dynamic
  encode_raw operations
@bizfsc bizfsc force-pushed the fix/mypy-type-fixes branch from 7d78ff8 to b43cf9f Compare April 29, 2026 19:39
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.

1 participant