Skip to content

od: Extend physical conversion to integer factors, fix typing#673

Open
acolomb wants to merge 7 commits into
canopen-python:masterfrom
acolomb:phys-passthrough
Open

od: Extend physical conversion to integer factors, fix typing#673
acolomb wants to merge 7 commits into
canopen-python:masterfrom
acolomb:phys-passthrough

Conversation

@acolomb
Copy link
Copy Markdown
Member

@acolomb acolomb commented Jun 4, 2026

The Variable.phys property docstring mentions "Non integers will be
passed as is." That is correct, but not reflected in the type hints
for the associated ODVariable.encode_phys() / .decode_phys()
functions. Extend the return / argument type to all possible internal
data types, instead of plain int.

Try factor conversion on all NUMBER_TYPES, where it was previously
limited to INTEGER_TYPES. Only apply rounding in encode_phys() if the
variable's data type is actually integer-based.

Allow integer factors in type hint for ODVariable.factor. There is
nothing wrong with using integer factors to yield integers
when decoding. For encoding, the division may still result in a
float, while the rounding behavior is kept unchanged for integer-typed
variables.

Thus, try to parse integer factors as integers from EDS files, not forcing
to a float.

Related comment first given here: #651 (comment)

acolomb added 4 commits June 4, 2026 22:48
The Variable.phys property docstring mentions "Non integers will be
passed as is."  That is correct, but not reflected in the type hints
for the associated ODVariable.encode_phys() / .decode_phys()
functions.  Extend the return / argument type to all possible internal
data types, instead of plain int.
Try factor conversion on all NUMBER_TYPES, where it was previously
limited to INTEGER_TYPES.  Only apply rounding in encode_phys() if the
variable's data type is actually integer-based.
There is nothing wrong with using integer factors to yield integers
when decoding.  For encoding, the division may still result in a
float, while the rounding behavior is kept unchanged for integer-typed
variables.
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@acolomb acolomb marked this pull request as ready for review June 4, 2026 21:36
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