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... |
zanieb
left a comment
There was a problem hiding this comment.
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.pathmodification between imports at the top of a file. This is a frequent cause of# noqa: E402false 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.pathmodifications, but that should be a separate rule.)Closes: #5557.