-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow sys.path
modifications between imports
#9047
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RUF100 | 23 | 23 | 0 | 0 | 0 |
E402 | 2 | 0 | 2 | 0 | 0 |
I think these are all improvements -- it's nice to see so many |
9e14c1d
to
1eb6fec
Compare
sys.path
modifications between imports
1eb6fec
to
8b8c4ad
Compare
I gated this to preview for now (ecosystem checks are still updating at time of writing), though honestly I'd be okay with shipping it to stable... |
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.
Nice! I think preview makes sense for this change.
Looking at the ecosystem checks with entrypoint scripts and tests, this makes even more sense |
Why modify |
Hi @tooruu I'd recommend looking through the ecosystem checks as some of this usage is entirely valid. We're not encouraging this behavior, we're simply fixing a false positive for a different lint rule. We can introduce a separate rule to suggest not making |
Summary
It's common to interleave a
sys.path
modification between imports at the top of a file. This is a frequent cause of# noqa: E402
false positives, as seen in the ecosystem checks. This PR modifies E402 to omit such modifications when determining the "import boundary".(We could consider linting against
sys.path
modifications, but that should be a separate rule.)Closes: #5557.