-
-
Notifications
You must be signed in to change notification settings - Fork 750
Description
We're using a lot of relative imports in this package and we're not very consistent about when and how to use which. Counting occurrences in the entire code base slightly favours absolute imports (about 56%).
PEP8 recommends the usage of absolute imports over relative imports unless a complex package layout would require unnecessarily verbose import statements
Absolute imports are recommended, as they are usually more readable and tend to be better behaved (or at least give better error messages) if the import system is incorrectly configured (such as when a directory inside a package ends up on sys.path):
[...]
However, 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:
I personally prefer absolute imports since they are much less ambiguous and portable.
For instance, there are 24 from .core import and four from ..core import statements and we have six core.py files. It's not hard to figure out where the imports are pointing to but an absolute version removes ambiguity, especially for multi-level relative references
If we go for absolute imports, a follow up question would be whether we want to automate this, e.g. https://github.com/MarcoGorelli/absolufy-imports
Thoughts?