Skip to content

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

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

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

Conversation

@acolomb

@acolomb acolomb commented Jun 4, 2026

Copy link
Copy Markdown
Member

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)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

typing Concerns typing information to be consumed by library users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants