-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Is your feature request related to a problem? Please describe.
The except clause can accept a parenthesised tuple of exceptions. However, in the case of only a single exception the brackets should be removed.
Black currently leaves both of these examples unchanged:
a = 1
try:
a.something
except (AttributeError) as err:
raise err
and
a = 1
try:
a.something
except (AttributeError,) as err:
raise err
Describe the solution you'd like
I would expect both examples to be corrected to:
a = 1
try:
a.something
except AttributeError as err:
raise err
Describe alternatives you've considered
I could see an argument to leave the tuple example (with the trailing comma) as is, maybe the user wants to add more exceptions in the future. Easy either way on that one, but we should at least fix the first (non-tuple) example.
Additional context
I actually came across this when someone assumed the except was a function in a PR. Black added the space before the brackets, but also removing the brackets would really help highlight that it's a keyword not a function 😄
try:
a.something
except(AttributeError) as err:
raise err