Skip to content

od: Robust path handling without type errors#669

Open
acolomb wants to merge 7 commits into
canopen-python:masterfrom
acolomb:fix-od-typing-filelike
Open

od: Robust path handling without type errors#669
acolomb wants to merge 7 commits into
canopen-python:masterfrom
acolomb:fix-od-typing-filelike

Conversation

@acolomb
Copy link
Copy Markdown
Member

@acolomb acolomb commented May 26, 2026

Fix the union-attr errors squelched in #651 properly. In the process, extend import_od() to gracefully handle some edge cases around missing file names and non-str paths in the source argument.

Extend unit tests around import and export functions. Note that these are still a bit convoluted because the EDS import is tested through the generic, format-agnostic OD API. This is still much easier than splitting tests between generic and format-specific though. If ever someone adds unit tests covering the EPF import, that might need some refactoring.

acolomb added 6 commits May 26, 2026 14:19
Static type checking cannot see the relationship between the
opened_here local variable and the type of object passed as dest
parameter to export_od().  Switch to storing another reference to the
opened file-like object instead of a boolean to avoid a [union-attr]
error.
Utilize the standard library's os.path.splitext() function to find the
file name suffix and treat it case-insensitively.
Utilize the standard library's os.path.splitext() function to find the
file name suffix (case-insensitive).

Fix a [union-attr] static type check error using an empty string as
fallback for the file name on file-like objects.  The annotated TextIO
type does provide it, but mypy cannot infer that connection between
with the "read" method being available.  Failing with the ValueError
in case the attribute is missing is still better than letting out an
AttributeError.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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