Skip to content

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
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, 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.


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

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.


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

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 canopen-python:master May 15, 2024
@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