-
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 8c49235
Showing
9 changed files
with
251 additions
and
208 deletions.
There are no files selected for viewing
37 changes: 30 additions & 7 deletions
37
...s/test/fixtures/flake8_simplify/SIM105.py → ...test/fixtures/flake8_simplify/SIM105_0.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
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
170 changes: 0 additions & 170 deletions
170
...ules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM105_SIM105.py.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.