-
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 SIM105 autofixes that would remove comments
- Loading branch information
1 parent
7b91a16
commit 3baff99
Showing
7 changed files
with
190 additions
and
147 deletions.
There are no files selected for viewing
37 changes: 30 additions & 7 deletions
37
crates/ruff/resources/test/fixtures/flake8_simplify/SIM105.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 |
---|---|---|
@@ -1,73 +1,96 @@ | ||
def foo(): | ||
pass | ||
|
||
|
||
# SIM105 | ||
try: | ||
foo() | ||
except ValueError: # SIM105 | ||
except ValueError: | ||
pass | ||
|
||
# SIM105 | ||
try: | ||
foo() | ||
except (ValueError, OSError): # SIM105 | ||
except (ValueError, OSError): | ||
pass | ||
|
||
# SIM105 | ||
try: | ||
foo() | ||
except: # SIM105 | ||
except: | ||
pass | ||
|
||
# SIM105 | ||
try: | ||
foo() | ||
except (a.Error, b.Error): # SIM105 | ||
except (a.Error, b.Error): | ||
pass | ||
|
||
# OK | ||
try: | ||
foo() | ||
except ValueError: | ||
print('foo') | ||
print("foo") | ||
except OSError: | ||
pass | ||
|
||
# OK | ||
try: | ||
foo() | ||
except ValueError: | ||
pass | ||
else: | ||
print('bar') | ||
print("bar") | ||
|
||
# OK | ||
try: | ||
foo() | ||
except ValueError: | ||
pass | ||
finally: | ||
print('bar') | ||
print("bar") | ||
|
||
# OK | ||
try: | ||
foo() | ||
foo() | ||
except ValueError: | ||
pass | ||
|
||
# OK | ||
try: | ||
for i in range(3): | ||
foo() | ||
except ValueError: | ||
pass | ||
|
||
|
||
def bar(): | ||
# OK | ||
try: | ||
return foo() | ||
except ValueError: | ||
pass | ||
|
||
|
||
def with_ellipsis(): | ||
# OK | ||
try: | ||
foo() | ||
except ValueError: | ||
... | ||
|
||
|
||
def with_ellipsis_and_return(): | ||
# OK | ||
try: | ||
return foo() | ||
except ValueError: | ||
... | ||
|
||
|
||
def with_comment(): | ||
try: | ||
foo() | ||
except (ValueError, OSError): | ||
pass # Trailing comment. |
3 changes: 2 additions & 1 deletion
3
crates/ruff/resources/test/fixtures/flake8_simplify/SIM105_1.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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"""Case: There's a random import, so it should add `contextlib` after it.""" | ||
import math | ||
|
||
# SIM105 | ||
try: | ||
math.sqrt(-1) | ||
except ValueError: # SIM105 | ||
except ValueError: | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ def foo(): | |
pass | ||
|
||
|
||
# SIM105 | ||
try: | ||
foo() | ||
except ValueError: | ||
|
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
Oops, something went wrong.