mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 12:25:45 +00:00
Format comment before parameter default correctly (#7870)
**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.
This commit is contained in:
parent
cb06b7956c
commit
3944c42d4c
3 changed files with 126 additions and 1 deletions
|
|
@ -390,6 +390,32 @@ try:
|
|||
#comment
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/7603
|
||||
def default_arg_comments(
|
||||
a: str = #a
|
||||
"a",
|
||||
b: str =
|
||||
#b
|
||||
"b",
|
||||
c: str =( #c
|
||||
"c"
|
||||
),
|
||||
d: str =(
|
||||
#d
|
||||
"d"
|
||||
)
|
||||
):
|
||||
print(a, b, c, d)
|
||||
|
||||
def default_arg_comments2(#
|
||||
x: int#=
|
||||
= #
|
||||
#
|
||||
123#
|
||||
#
|
||||
):
|
||||
print(x)
|
||||
```
|
||||
|
||||
## Output
|
||||
|
|
@ -940,6 +966,33 @@ try:
|
|||
# comment
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/7603
|
||||
def default_arg_comments(
|
||||
a: str = # a
|
||||
"a",
|
||||
b: str =
|
||||
# b
|
||||
"b",
|
||||
c: str = ( # c
|
||||
"c"
|
||||
),
|
||||
d: str = (
|
||||
# d
|
||||
"d"
|
||||
),
|
||||
):
|
||||
print(a, b, c, d)
|
||||
|
||||
|
||||
def default_arg_comments2( #
|
||||
x: int = # = #
|
||||
#
|
||||
123, #
|
||||
#
|
||||
):
|
||||
print(x)
|
||||
```
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue