-
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.
Avoid re-using imports beyond current edit size
- Loading branch information
1 parent
51278dd
commit 410e489
Showing
6 changed files
with
49 additions
and
21 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
crates/ruff/resources/test/fixtures/flake8_simplify/SIM105_3.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,16 @@ | ||
"""Case: `contextlib` is imported after the call site.""" | ||
|
||
|
||
def foo(): | ||
pass | ||
|
||
|
||
def bar(): | ||
# SIM105 | ||
try: | ||
foo() | ||
except ValueError: | ||
pass | ||
|
||
|
||
import contextlib |
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
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
17 changes: 17 additions & 0 deletions
17
...es/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM105_SIM105_3.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,17 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_simplify/mod.rs | ||
--- | ||
SIM105_3.py:10:5: SIM105 Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass` | ||
| | ||
10 | def bar(): | ||
11 | # SIM105 | ||
12 | try: | ||
| _____^ | ||
13 | | foo() | ||
14 | | except ValueError: | ||
15 | | pass | ||
| |____________^ SIM105 | ||
| | ||
= help: Replace with `contextlib.suppress(ValueError)` | ||
|
||
|