-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Formatter instability: own-line comments on function parameter defaults #7603
Comments
It may also be possible (at last for case 1) to enforce a hard line break if the default value has a leading comment. |
The challenge there is that the leading comment could be within parentheses. |
I see. Would be good if we have a solution for this that works consistently. E.g. a |
As a diff ---
--- Formatted once
+++ Formatted twice
@@ -1,13 +1,11 @@
def f2(
- x: e2 = #
- "foo",
+ x: e2 = "foo", #
) -> r2:
pass
def f3( #
- x: e3 = # # = #
- 123, #
+ x: e3 = 123, # # = # #
#
) -> r3:
pass
---
|
Keeping this for the Beta. It's likely uncommon but should be fixed. |
**Handle comment before the default values of function parameters correctly by inserting a line break instead of space after the equals sign where required. ```python def f( a = # parameter trailing comment; needs line break (1) 1, b = # default leading comment; needs line break (2) 2, c = ( # the default leading can only be end-of-line with parentheses; no line break 3 ), d = ( # own line leading comment with parentheses; no line break 4 ) ) ``` Fixes #7603 **Test Plan** Added the different cases and one more complex case as fixtures.
**Summary** Handle comment before the default values of function parameters correctly by inserting a line break instead of space after the equals sign where required. ```python def f( a = # parameter trailing comment; needs line break 1, b = # default leading comment; needs line break 2, c = ( # the default leading can only be end-of-line with parentheses; no line break 3 ), d = ( # own line leading comment with parentheses; no line break 4 ) ) ``` Fixes #7603 **Test Plan** Added the different cases and one more complex case as fixtures.
Given:
We first format as:
And then as:
We probably need to treat those comments as dangling, as for comments around colons.
Sourced from #7590 (
A_870428921595896654.py
).The text was updated successfully, but these errors were encountered: