Skip to content

Conversation

@sveinse
Copy link
Collaborator

@sveinse sveinse commented Mar 25, 2023

This PR adds with contexts to the usage of open. A context handles closing automatically, making the call to close superfluous.

Ths PR also fixes issue with close in objectdictionary/init.py and eds.py. export_od() and import_eds() should not close file handles that is not opened within these functions.

Copy link
Member

@acolomb acolomb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall from a quick glance. I guess if people relied on these functions closing their file handle for them, that's rather weird, but was it documented? I can't imagine many cases where it would matter, but let's hear some more thoughts on whether this behavior change needs a bit of a migration path to avoid breaking existing code on upgrade.

@sveinse
Copy link
Collaborator Author

sveinse commented Apr 5, 2023

I see the PR is approved. Is this PR waiting on any input or action from me?

@christiansandberg christiansandberg merged commit f687e2d into canopen-python:master Apr 6, 2023
Copy link
Collaborator Author

@sveinse sveinse Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small snag: Since this PR was created before the isinstance() fix was merged, this PR was created with type(). This statement should ideally be changed to ensure proper isinstance() use:

    # If dest is opened in this fn, it should be closed
    if isinstance(dest, str):
        dest.close()

@sveinse sveinse deleted the feature-open-contexts branch April 26, 2024 01:06
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.

3 participants