forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip
PERF203
violations for multi-statement loops (astral-sh#6145)
Closes astral-sh#5858.
- Loading branch information
1 parent
ad3081d
commit 74cdfdb
Showing
3 changed files
with
23 additions
and
39 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 |
---|---|---|
@@ -1,28 +1,23 @@ | ||
# PERF203 | ||
for i in range(10): | ||
try: # PERF203 | ||
try: | ||
print(f"{i}") | ||
except: | ||
print("error") | ||
|
||
# OK | ||
try: | ||
for i in range(10): | ||
print(f"{i}") | ||
except: | ||
print("error") | ||
|
||
# OK | ||
i = 0 | ||
while i < 10: # PERF203 | ||
while i < 10: | ||
try: | ||
print(f"{i}") | ||
except: | ||
print("error") | ||
|
||
i += 1 | ||
|
||
try: | ||
i = 0 | ||
while i < 10: | ||
print(f"{i}") | ||
i += 1 | ||
except: | ||
print("error") |
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
26 changes: 7 additions & 19 deletions
26
...s/ruff/src/rules/perflint/snapshots/ruff__rules__perflint__tests__PERF203_PERF203.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 |
---|---|---|
@@ -1,28 +1,16 @@ | ||
--- | ||
source: crates/ruff/src/rules/perflint/mod.rs | ||
--- | ||
PERF203.py:4:5: PERF203 `try`-`except` within a loop incurs performance overhead | ||
PERF203.py:5:5: PERF203 `try`-`except` within a loop incurs performance overhead | ||
| | ||
2 | try: # PERF203 | ||
3 | print(f"{i}") | ||
4 | except: | ||
3 | try: | ||
4 | print(f"{i}") | ||
5 | except: | ||
| _____^ | ||
5 | | print("error") | ||
6 | | print("error") | ||
| |______________________^ PERF203 | ||
6 | | ||
7 | try: | ||
7 | | ||
8 | # OK | ||
| | ||
|
||
PERF203.py:17:5: PERF203 `try`-`except` within a loop incurs performance overhead | ||
| | ||
15 | try: | ||
16 | print(f"{i}") | ||
17 | except: | ||
| _____^ | ||
18 | | print("error") | ||
| |______________________^ PERF203 | ||
19 | | ||
20 | i += 1 | ||
| | ||
|
||
|