Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up imports of old modules #433

Merged
merged 1 commit into from
May 15, 2024

Conversation

sveinse
Copy link
Collaborator

@sveinse sveinse commented May 15, 2024

The canopen package have import leftovers from earlier versions of Python. This PR cleans up the no longer valid imports.

  • import Queue dates to py 2
  • import collections.*Mapping was changed to collections.abc.*Mapping in py 3.3
  • import ConfigParser dates to py 2
  • import xml.etree.cElementTree is deprecated since py 3.3. It will pick the fastest option when using xml.etree.ElementTree
  • Fixed .base into canopen.pdo.base in canopen/pdo/init.py
  • Fixed .base into canopen.sdo.base in canopen/sdo/init.py

Copy link
Collaborator

@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, but I'd like some discussion / reasoning about using absolute imports within the same package. DRY tells us to leave out the package name in places within the same package, and I've seen very few use cases where relative imports don't work.

@@ -4,7 +4,7 @@
from canopen.pdo.base import PdoBase, Maps

# Compatibility
from .base import Variable
from canopen.pdo.base import Variable
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why change to absolute package reference here? I'd actually rather go the other way and use relative imports within the same package. Maybe it's a matter of taste, but I liked the old style.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No other reason that PEP 8 recommends using absolute imports, so it's become a habit for many projects. PEP 8 also states "explicit relative imports are an acceptable alternative to absolute imports, especially when dealing with complex package layouts where using absolute imports would be unnecessarily verbose". So either is acceptable, but with preference to the former. And lastly, the rest of canopen is using absolute imports. I find it messy that the import styles are mixed.

@@ -4,4 +4,4 @@
from canopen.sdo.exceptions import SdoAbortedError, SdoCommunicationError

# Compatibility
from .base import Variable, Record, Array
from canopen.sdo.base import Variable, Record, Array
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

@acolomb acolomb merged commit 26a68b5 into christiansandberg:master May 15, 2024
1 check passed
@sveinse sveinse deleted the feature-cleanup-imports branch May 15, 2024 21:02
@acolomb acolomb added this to the v2.3.0 milestone Jun 11, 2024
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.

2 participants