Closed obackhouse closed 1 year ago
Also waiting on #92 so I can make sure ebcc
is handled consistently
Patch coverage: 96.33
% and project coverage change: -0.16
:warning:
Comparison is base (
ed2f91f
) 72.12% compared to head (079885a
) 71.97%.
:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
I would say relative imports are OK as long as they are explicit (with a leading .
)
and a limited number of star imports are OK, if the imported module defines __all__
.
What's the reason to get rid of them?
PEP 8 recommends against relative imports:
Relative imports for intra-package imports are highly discouraged. Always use the absolute package path for all imports.
Absolute imports make it easier to avoid circular importing issues in complex packages.
As for star imports, PEP 8 does not explicitly mention them as far as I know, however in my opinion (and I think it's a common opinion) they're a bad idea. Not only do they pollute the namespace of the module, but they make it extremely difficult to chase down the origin of imported classes and methods, and generally reduce readability. They also prevent some static analysis and flaking tools on top of that.
I think in both cases, given that you can achieve the same behaviour with explicit and absolute imports, the latter is just the better option.
I certainly agree that following an execution thread of someone else's code is more difficult with star imports. But maybe thats because I'm still not using an IDE...
@obackhouse Where did you find this quote in PEP 8? Was it maybe a Python 2 version, before we had the dot-syntax? https://peps.python.org/pep-0008/#imports says
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 don't have strong feelings about the star import, I agree they should generally be avoided. Side note @ghb24 I now switched to PyCharm after so many years of vim it's the best thing ever :grin: (just install ideavim to keep the commands)
@maxnus yes maybe you're right, that's outdated PEP 8. That being said, any decent linter or formatter will force absolute imports, since they're more readable (except for the fact they're longer, I guess). I guess that doesn't bode well for my renewed plans to format Vayesta...
If you have strong feelings, I can revert the relative imports.
I think there is a decent benefit to consistency in our code, and I would err on the side of absolute imports just for clarity's sake. While relative imports are definitely sometimes easier to write, given the plethora of tools to allow automatic conversion between relative imports and absolute imports (including in PyCharm, which I'm glad @maxnus has finally come around to using!).
@maxnus I've just removed all the unused imports in https://github.com/BoothGroup/Vayesta/pull/96/commits/f5426de0866bd9d6c9a49bda185a40cee5074b69, I excluded __init__.py
files - can you think of any other instances that there may be unused imports that are desired or does this sound OK?
@obackhouse : Conflicts now with updated master...
@obackhouse : Conflicts now with updated master...
I'll sort it, don't think I'm done just yet anyway
Good to merge now
Improves handling of optional dependencies including on installation, and will hopefully remove relative and star imports once I am done