-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't treat straight imports of __future__ as
__future__
imports (#…
…5128) ## Summary If you `import __future__`, it's not subject to the same rules as `from __future__ import feature` -- i.e., this is fine: ```python x = 1 import __future__ ``` It doesn't really make sense to treat these as `__future__` imports (though I can't imagine anyone ever does this anyway).
- Loading branch information
1 parent
1e38348
commit 1f856aa
Showing
5 changed files
with
35 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""Test that straight `__future__` imports are considered unused.""" | ||
|
||
|
||
def f(): | ||
import __future__ | ||
|
||
|
||
def f(): | ||
import __future__ | ||
|
||
print(__future__.absolute_import) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_18.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
source: crates/ruff/src/rules/pyflakes/mod.rs | ||
--- | ||
F401_18.py:5:12: F401 [*] `__future__` imported but unused | ||
| | ||
4 | def f(): | ||
5 | import __future__ | ||
| ^^^^^^^^^^ F401 | ||
| | ||
= help: Remove unused import: `future` | ||
|
||
ℹ Fix | ||
2 2 | | ||
3 3 | | ||
4 4 | def f(): | ||
5 |- import __future__ | ||
5 |+ pass | ||
6 6 | | ||
7 7 | | ||
8 8 | def f(): | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters