-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unnecessary parentheses from
except
clauses (#2939)
Co-authored-by: Jelle Zijlstra <[email protected]>
- Loading branch information
1 parent
14d84ba
commit bd1e980
Showing
4 changed files
with
87 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# These brackets are redundant, therefore remove. | ||
try: | ||
a.something | ||
except (AttributeError) as err: | ||
raise err | ||
|
||
# This is tuple of exceptions. | ||
# Although this could be replaced with just the exception, | ||
# we do not remove brackets to preserve AST. | ||
try: | ||
a.something | ||
except (AttributeError,) as err: | ||
raise err | ||
|
||
# This is a tuple of exceptions. Do not remove brackets. | ||
try: | ||
a.something | ||
except (AttributeError, ValueError) as err: | ||
raise err | ||
|
||
# Test long variants. | ||
try: | ||
a.something | ||
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err: | ||
raise err | ||
|
||
try: | ||
a.something | ||
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,) as err: | ||
raise err | ||
|
||
try: | ||
a.something | ||
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err: | ||
raise err | ||
|
||
# output | ||
# These brackets are redundant, therefore remove. | ||
try: | ||
a.something | ||
except AttributeError as err: | ||
raise err | ||
|
||
# This is tuple of exceptions. | ||
# Although this could be replaced with just the exception, | ||
# we do not remove brackets to preserve AST. | ||
try: | ||
a.something | ||
except (AttributeError,) as err: | ||
raise err | ||
|
||
# This is a tuple of exceptions. Do not remove brackets. | ||
try: | ||
a.something | ||
except (AttributeError, ValueError) as err: | ||
raise err | ||
|
||
# Test long variants. | ||
try: | ||
a.something | ||
except ( | ||
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error | ||
) as err: | ||
raise err | ||
|
||
try: | ||
a.something | ||
except ( | ||
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, | ||
) as err: | ||
raise err | ||
|
||
try: | ||
a.something | ||
except ( | ||
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, | ||
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, | ||
) as err: | ||
raise err |
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