-
Notifications
You must be signed in to change notification settings - Fork 19
adopt flake8-tidy-imports to enforce O.1.5 #223
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
adopt flake8-tidy-imports to enforce O.1.5 #223
Conversation
|
Thank you for contributing! 👋 |
|
The review-bot was supposed to tag the NI engineers for comment due to this changing the Conventions doc: |
neilvana
left a comment
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.
I'm in favor of adding the checking. We just need to clarify the exception around __init__.py.
eb1c172 to
855fda2
Compare
855fda2 to
a7f2f30
Compare

Reason
We have O.1.5 which says:
We don't have enforcement of this.
If a non-absolute import is used, our current tooling (
fixandformat) has different behavior depending on if it is run above the module (in the folder withpyproject.toml) or in a sub-folder within the module. This is (in part) caused by us setting theapp-import-namesautomatically if the user does not specify it. (and we don't include neighbor sub-modules).This PR is a way to address
#215
Adopting
flake8-tidy-imports+ explicitly setting it to ban "all relative" imports, the case mentioned in that issue is dealt with by flagging that "neighbor" import with I252.Pros:
Simple, opinionated rule
Cons:
(this example assumes a layout similar to):
As PEP328 defines it, if the import "import foo" is present, it is considered to be an absolute import (even though the intention is to resolve to a neighboring sub-module); while, "import .foo" or "from . import foo" are both relative imports.
As
flake8-tidy-importsis currently implemented, this would also ban an "absolute" import that is meant to resolve to a neighbor.Rationale:
fizz.pyis ambiguous for human readers. Do we wantmodule.foo? or shouldfoobe coming from an install-time dep?subprocesssub-module, the codeimport subprocesswould resolve to this module's subprocess even if it was intended to resolve to stdlib. By adding this rule in, that would now be required to beimport module.subprocessorfrom module import subprocess.module) makes it clear that this is "first-party" and removes ambiguity over whether iSort is doing the right thing or not.