Remove redundant brackets from except
clause
#2937
Labels
F: parentheses
Too many parentheses, not enough parentheses, and so on.
S: accepted
The changes in this design / enhancement issue have been accepted and can be implemented
T: enhancement
New feature or request
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:
and
Describe the solution you'd like
I would expect both examples to be corrected to:
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 😄The text was updated successfully, but these errors were encountered: