-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement B036 check for
except BaseException
without re-raising (#438
) * Implement B036 check for `except BaseException` without re-raising * handle case where exception is re-raised by name. Fix unittests * recursively search for re-raise
- Loading branch information
Showing
6 changed files
with
111 additions
and
7 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
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
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,54 @@ | ||
|
||
try: | ||
pass | ||
except BaseException: # bad | ||
print("aaa") | ||
pass | ||
|
||
|
||
try: | ||
pass | ||
except BaseException as ex: # bad | ||
print(ex) | ||
pass | ||
|
||
|
||
try: | ||
pass | ||
except ValueError: | ||
raise | ||
except BaseException: # bad | ||
pass | ||
|
||
|
||
try: | ||
pass | ||
except BaseException: # ok - reraised | ||
print("aaa") | ||
raise | ||
|
||
|
||
try: | ||
pass | ||
except BaseException as ex: # bad - raised something else | ||
print("aaa") | ||
raise KeyError from ex | ||
|
||
try: | ||
pass | ||
except BaseException as e: | ||
raise e # ok - raising same thing | ||
|
||
try: | ||
pass | ||
except BaseException: | ||
if 0: | ||
raise # ok - raised somewhere within branch | ||
|
||
try: | ||
pass | ||
except BaseException: | ||
try: # nested try | ||
pass | ||
except ValueError: | ||
raise # bad - raising within a nested try/except, but not within the main one |
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