Fix placement of inline parameter comments (#13379)

This commit is contained in:
Micha Reiser 2024-09-18 08:26:06 +02:00 committed by GitHub
parent c7b2e336f0
commit 6ac61d7b89
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 419 additions and 63 deletions

View file

@ -458,3 +458,108 @@ def foo(x: S) -> S: ...
@decorator # comment
def foo(x: S) -> S: ...
# Regression tests for https://github.com/astral-sh/ruff/issues/13369
def foo(
arg: ( # comment with non-return annotation
int
# comment with non-return annotation
),
):
pass
def foo(
arg: ( # comment with non-return annotation
int
| range
| memoryview
# comment with non-return annotation
),
):
pass
def foo(arg: (
int
# only after
)):
pass
# Asserts that "incorrectly" placed comments don't *move* by fixing https://github.com/astral-sh/ruff/issues/13369
def foo(
# comment with non-return annotation
# comment with non-return annotation
arg: (int),
):
pass
# Comments between *args and **kwargs
def args_no_type_annotation(*
# comment
args): pass
def args_type_annotation(*
# comment
args: int): pass
def args_trailing_end_of_line_comment(* # comment
args): pass
def args_blank_line_comment(*
# comment
args): pass
def args_with_leading_parameter_comment(
# What comes next are arguments
*
# with an inline comment
args): pass
def kargs_no_type_annotation(**
# comment
kwargs): pass
def kwargs_type_annotation(**
# comment
kwargs: int): pass
def args_many_comments(
# before
*
# between * and name
args # trailing args
# after name
): pass
def args_many_comments_with_type_annotation(
# before
*
# between * and name
args # trailing args
# before colon
: # after colon
# before type
int # trailing type
# after type
): pass
def args_with_type_annotations_no_after_colon_comment(
# before
*
# between * and name
args # trailing args
# before colon
:
# before type
int # trailing type
# after type
): pass