-
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.
Add new checks for except (...): clauses (#105)
- Loading branch information
1 parent
04dd13b
commit e35343c
Showing
6 changed files
with
185 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
Should emit: | ||
B013 - on lines 10 and 28 | ||
""" | ||
|
||
import re | ||
|
||
try: | ||
pass | ||
except (ValueError,): | ||
# pointless use of tuple | ||
pass | ||
|
||
try: | ||
pass | ||
except (ValueError): | ||
# not using a tuple means it's OK (if odd) | ||
pass | ||
|
||
try: | ||
pass | ||
except ValueError: | ||
# no warning here, all good | ||
pass | ||
|
||
try: | ||
pass | ||
except (re.error,): | ||
# pointless use of tuple with dotted attribute | ||
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Should emit: | ||
B014 - on lines 10, 16, 27, 41, and 48 | ||
""" | ||
|
||
import re | ||
|
||
try: | ||
pass | ||
except (Exception, TypeError): | ||
# TypeError is a subclass of Exception, so it doesn't add anything | ||
pass | ||
|
||
try: | ||
pass | ||
except (OSError, OSError) as err: | ||
# Duplicate exception types are useless | ||
pass | ||
|
||
|
||
class MyError(Exception): | ||
pass | ||
|
||
|
||
try: | ||
pass | ||
except (MyError, MyError): | ||
# Detect duplicate non-builtin errors | ||
pass | ||
|
||
|
||
try: | ||
pass | ||
except (MyError, Exception) as e: | ||
# Don't assume that we're all subclasses of Exception | ||
pass | ||
|
||
|
||
try: | ||
pass | ||
except (MyError, BaseException) as e: | ||
# But we *can* assume that everything is a subclass of BaseException | ||
pass | ||
|
||
|
||
try: | ||
pass | ||
except (re.error, re.error): | ||
# Duplicate exception types as attributes | ||
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