-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fix trailing comma for function with one arg (#880) #891
Fix trailing comma for function with one arg (#880) #891
Conversation
781b6a2
to
c7943f2
Compare
(ref. issue #880 ) |
black.py
Outdated
if original.is_import: | ||
# Ensure a trailing comma for imports and standalone function arguments, but | ||
# be careful not to add one after any comments. | ||
no_commas = original.is_def and not [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use any()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, cheers.
tests/test_black.py
Outdated
@@ -264,6 +264,14 @@ def test_function2(self) -> None: | |||
black.assert_equivalent(source, actual) | |||
black.assert_stable(source, actual, black.FileMode()) | |||
|
|||
@patch("black.dump_to_file", dump_to_stderr) | |||
def test_function3(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to have another test file, but could you name it something less generic, like test_function_trailing_comma
?
Modified maybe_remove_trailing_comma to remove trailing commas for typedarglists (in addition to arglists), and updated line split logic to ensure that all lines in a function definition that contain only one arg have a trailing comma.
c7943f2
to
7e822f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for fixing this!
Modified maybe_remove_trailing_comma to remove trailing commas for typedarglists (in addition to arglists), and updated line split logic to ensure that all lines in a function definition that contain only one arg have a trailing comma.
Some discussion points:
no_commas
. Would be great to hear any other suggestions for this test.