-
Notifications
You must be signed in to change notification settings - Fork 572
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
CLN: use absolute imports throughout the codebase #1682
Conversation
Hi, |
Pull Request Test Coverage Report for Build 4161382935
💛 - Coveralls |
4c02e6c
to
717d60e
Compare
from . import xyz
) with absolute imports (from shapely import xyz
)from . import xyz
) with absolute imports (from shapely import xyz
)
@jorisvandenbossche please review |
@jorisvandenbossche can his be included in |
Personally, I have a (slight, but not strong) preference for keeping the relative imports, because I like using those (there are also several other projects that do that as well, like numpy and scikit-learn, although those projects might fit more in the "complex package layouts" bucket compared to shapely) There is certainly some inconsistency right now internally, because the usage of this has come from merging the pygeos code, while what remained from the original shapely code uses absolute imports. cc @caspervdw since you started using this originally in pygeos |
@jorisvandenbossche Thanks for your comments. Sorry, I'm not sure I follow what's the advantage of using relative imports (You noted that some other popular projects use them, but why is it an advantage? many other popular projects use absolute imports exclusively). The disadvantages that I know of, for using relative imports are:
|
Hi @jorisvandenbossche any further thoughts about this PR and with respect to #1711 ? |
c5dc66c
to
2512fcc
Compare
@brendan-ward @mwtoews @caspervdw any thoughts about this? |
Have not reviewed the PR (will try to do so in the coming days), but I agree with the direction; I stumbled with the relative imports in pygeos several times while trying to test code there, and the precedent for absolute imports was already set in shapely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @idanmiara ! Only spotted a couple of issues (not sure why isort
is putting unittest
into wrong position), but otherwise this looks good to me.
It brings a nice consistency to the imports, since the precedent was already established in shapely < 2.0
Please see #1681 which will fix that issue. |
…orts (`from shapely import xyz`) and run `isort` Co-authored-by: Brendan Ward <[email protected]>
6442117
to
4fadfe0
Compare
from . import xyz
) with absolute imports (from shapely import xyz
)
@brendan-ward please approve this PR as we are addressing your requested change in #1743 and #1681 |
@jorisvandenbossche @brendan-ward |
d3709e9
to
0c027b4
Compare
I was just giving those example to show that shapely is not some kind of oddity in using relative imports. It's not bad practice, it's just a subjective preference on development workflows (PEP8 recommends absolute imports, but also says that explicit relative ones are an "acceptable alternative"). But consistency within a code base is of course important.
Given that #1681 also includes updating the unittest import, I removed the changes to the |
Thanks @idanmiara |
@jorisvandenbossche thanks for your review! |
I'm late to say thanks, looks good @idanmiara ! I generally prefer absolute imports within modules and appreciate consistency. A modern tool of interest is https://github.com/MarcoGorelli/absolufy-imports |
Related to #1711
Replace relative imports (i.e.
from . import xyz
) with absolute imports (from shapely import xyz
) and runisort
as recommended by PEP8 (https://peps.python.org/pep-0008/#imports): Absolute imports are recommended, as they are usually more readable and tend to be better behaved.This helps much with debugging.