-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider
with
blocks as single-item branches (#12311)
## Summary Ensures that, e.g., the following is not considered a redefinition-without-use: ```python import contextlib foo = None with contextlib.suppress(ImportError): from some_module import foo ``` Closes #12309.
- Loading branch information
1 parent
940df67
commit 456d6a2
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
crates/ruff_linter/resources/test/fixtures/pyflakes/F811_31.py
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,21 @@ | ||
"""Regression test for: https://github.com/astral-sh/ruff/issues/12309""" | ||
|
||
import contextlib | ||
|
||
foo = None | ||
with contextlib.suppress(ImportError): | ||
from some_module import foo | ||
|
||
bar = None | ||
try: | ||
from some_module import bar | ||
except ImportError: | ||
pass | ||
|
||
|
||
try: | ||
baz = None | ||
|
||
from some_module import baz | ||
except ImportError: | ||
pass |
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
13 changes: 13 additions & 0 deletions
13
...er/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_31.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,13 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pyflakes/mod.rs | ||
--- | ||
F811_31.py:19:29: F811 Redefinition of unused `baz` from line 17 | ||
| | ||
17 | baz = None | ||
18 | | ||
19 | from some_module import baz | ||
| ^^^ F811 | ||
20 | except ImportError: | ||
21 | pass | ||
| | ||
= help: Remove definition: `baz` |