-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Single-argument function includes trailing comma inconsistently #4080
Comments
Thanks. I think we should always add a trailing comma here. |
I would argue that Black preserving the trailing comma would be more consistent with the overall behavior of Black. For example, both of these function calls are acceptable to Black:
The reason for this is that lists of things is one of the places that Black gives users a choice of formatting: (1) I want as few of lines as possible, (2) one line per item. This creates an ambiguity when there is only one element: Did the user intend to choose the everything-on-one-line option (no comma) or did the user intend to choose the split-elements-across-lines option (trailing comma)? Everywhere else, Black resolves this ambiguity by preserving trailing commas, and I think it should do that in function definitions too, even single parameter functions. |
@drhagen possibly, but we already add the trailing comma for non-annotated parameters, and if nothing else we should be consistent.
|
Describe the bug
When a single-argument function definition breaks across multiple lines, Black will add a trailing comma (after the argument) in some cases but not others.
To Reproduce
For example, given the following Black adds a trailing comma after the annotation on
x
in the first case, but not the second, third, or fourth:So the inclusion of the trailing comma seems to depend on the content of the annotation (but not its length). One observation: Black omits the trailing comma when the annotation itself contains a comma.
(Here's the same example in the playground.)
The text was updated successfully, but these errors were encountered: