mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Update Black tests (#8901)
This commit is contained in:
parent
08f3110f1e
commit
fd70cd789f
435 changed files with 21436 additions and 1595 deletions
14
crates/ruff_python_formatter/resources/test/fixtures/black/cases/bytes_docstring.py
vendored
Normal file
14
crates/ruff_python_formatter/resources/test/fixtures/black/cases/bytes_docstring.py
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
def bitey():
|
||||||
|
b" not a docstring"
|
||||||
|
|
||||||
|
def bitey2():
|
||||||
|
b' also not a docstring'
|
||||||
|
|
||||||
|
def triple_quoted_bytes():
|
||||||
|
b""" not a docstring"""
|
||||||
|
|
||||||
|
def triple_quoted_bytes2():
|
||||||
|
b''' also not a docstring'''
|
||||||
|
|
||||||
|
def capitalized_bytes():
|
||||||
|
B" NOT A DOCSTRING"
|
18
crates/ruff_python_formatter/resources/test/fixtures/black/cases/bytes_docstring.py.expect
vendored
Normal file
18
crates/ruff_python_formatter/resources/test/fixtures/black/cases/bytes_docstring.py.expect
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
def bitey():
|
||||||
|
b" not a docstring"
|
||||||
|
|
||||||
|
|
||||||
|
def bitey2():
|
||||||
|
b" also not a docstring"
|
||||||
|
|
||||||
|
|
||||||
|
def triple_quoted_bytes():
|
||||||
|
b""" not a docstring"""
|
||||||
|
|
||||||
|
|
||||||
|
def triple_quoted_bytes2():
|
||||||
|
b""" also not a docstring"""
|
||||||
|
|
||||||
|
|
||||||
|
def capitalized_bytes():
|
||||||
|
b" NOT A DOCSTRING"
|
111
crates/ruff_python_formatter/resources/test/fixtures/black/cases/comments_in_blocks.py
vendored
Normal file
111
crates/ruff_python_formatter/resources/test/fixtures/black/cases/comments_in_blocks.py
vendored
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
# Test cases from:
|
||||||
|
# - https://github.com/psf/black/issues/1798
|
||||||
|
# - https://github.com/psf/black/issues/1499
|
||||||
|
# - https://github.com/psf/black/issues/1211
|
||||||
|
# - https://github.com/psf/black/issues/563
|
||||||
|
|
||||||
|
(
|
||||||
|
lambda
|
||||||
|
# a comment
|
||||||
|
: None
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
lambda:
|
||||||
|
# b comment
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
lambda
|
||||||
|
# a comment
|
||||||
|
:
|
||||||
|
# b comment
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
|
[
|
||||||
|
x
|
||||||
|
# Let's do this
|
||||||
|
for
|
||||||
|
# OK?
|
||||||
|
x
|
||||||
|
# Some comment
|
||||||
|
# And another
|
||||||
|
in
|
||||||
|
# One more
|
||||||
|
y
|
||||||
|
]
|
||||||
|
|
||||||
|
return [
|
||||||
|
(offers[offer_index], 1.0)
|
||||||
|
for offer_index, _
|
||||||
|
# avoid returning any offers that don't match the grammar so
|
||||||
|
# that the return values here are consistent with what would be
|
||||||
|
# returned in AcceptValidHeader
|
||||||
|
in self._parse_and_normalize_offers(offers)
|
||||||
|
]
|
||||||
|
|
||||||
|
from foo import (
|
||||||
|
bar,
|
||||||
|
# qux
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def convert(collection):
|
||||||
|
# replace all variables by integers
|
||||||
|
replacement_dict = {
|
||||||
|
variable: f"{index}"
|
||||||
|
for index, variable
|
||||||
|
# 0 is reserved as line terminator
|
||||||
|
in enumerate(collection.variables(), start=1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
i: i
|
||||||
|
for i
|
||||||
|
# a comment
|
||||||
|
in range(5)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_subtree_proof_nodes(
|
||||||
|
chunk_index_groups: Sequence[Tuple[int, ...], ...],
|
||||||
|
) -> Tuple[int, ...]:
|
||||||
|
subtree_node_paths = (
|
||||||
|
# We take a candidate element from each group and shift it to
|
||||||
|
# remove the bits that are not common to other group members, then
|
||||||
|
# we convert it to a tree path that all elements from this group
|
||||||
|
# have in common.
|
||||||
|
chunk_index
|
||||||
|
for chunk_index, bits_to_truncate
|
||||||
|
# Each group will contain an even "power-of-two" number of# elements.
|
||||||
|
# This tells us how many tailing bits each element has# which need to
|
||||||
|
# be truncated to get the group's common prefix.
|
||||||
|
in ((group[0], (len(group) - 1).bit_length()) for group in chunk_index_groups)
|
||||||
|
)
|
||||||
|
return subtree_node_paths
|
||||||
|
|
||||||
|
|
||||||
|
if (
|
||||||
|
# comment1
|
||||||
|
a
|
||||||
|
# comment2
|
||||||
|
or (
|
||||||
|
# comment3
|
||||||
|
(
|
||||||
|
# comment4
|
||||||
|
b
|
||||||
|
)
|
||||||
|
# comment5
|
||||||
|
and
|
||||||
|
# comment6
|
||||||
|
c
|
||||||
|
or (
|
||||||
|
# comment7
|
||||||
|
d
|
||||||
|
)
|
||||||
|
)
|
||||||
|
):
|
||||||
|
print("Foo")
|
111
crates/ruff_python_formatter/resources/test/fixtures/black/cases/comments_in_blocks.py.expect
vendored
Normal file
111
crates/ruff_python_formatter/resources/test/fixtures/black/cases/comments_in_blocks.py.expect
vendored
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
# Test cases from:
|
||||||
|
# - https://github.com/psf/black/issues/1798
|
||||||
|
# - https://github.com/psf/black/issues/1499
|
||||||
|
# - https://github.com/psf/black/issues/1211
|
||||||
|
# - https://github.com/psf/black/issues/563
|
||||||
|
|
||||||
|
(
|
||||||
|
lambda
|
||||||
|
# a comment
|
||||||
|
: None
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
lambda:
|
||||||
|
# b comment
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
lambda
|
||||||
|
# a comment
|
||||||
|
:
|
||||||
|
# b comment
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
|
[
|
||||||
|
x
|
||||||
|
# Let's do this
|
||||||
|
for
|
||||||
|
# OK?
|
||||||
|
x
|
||||||
|
# Some comment
|
||||||
|
# And another
|
||||||
|
in
|
||||||
|
# One more
|
||||||
|
y
|
||||||
|
]
|
||||||
|
|
||||||
|
return [
|
||||||
|
(offers[offer_index], 1.0)
|
||||||
|
for offer_index, _
|
||||||
|
# avoid returning any offers that don't match the grammar so
|
||||||
|
# that the return values here are consistent with what would be
|
||||||
|
# returned in AcceptValidHeader
|
||||||
|
in self._parse_and_normalize_offers(offers)
|
||||||
|
]
|
||||||
|
|
||||||
|
from foo import (
|
||||||
|
bar,
|
||||||
|
# qux
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def convert(collection):
|
||||||
|
# replace all variables by integers
|
||||||
|
replacement_dict = {
|
||||||
|
variable: f"{index}"
|
||||||
|
for index, variable
|
||||||
|
# 0 is reserved as line terminator
|
||||||
|
in enumerate(collection.variables(), start=1)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
i: i
|
||||||
|
for i
|
||||||
|
# a comment
|
||||||
|
in range(5)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_subtree_proof_nodes(
|
||||||
|
chunk_index_groups: Sequence[Tuple[int, ...], ...],
|
||||||
|
) -> Tuple[int, ...]:
|
||||||
|
subtree_node_paths = (
|
||||||
|
# We take a candidate element from each group and shift it to
|
||||||
|
# remove the bits that are not common to other group members, then
|
||||||
|
# we convert it to a tree path that all elements from this group
|
||||||
|
# have in common.
|
||||||
|
chunk_index
|
||||||
|
for chunk_index, bits_to_truncate
|
||||||
|
# Each group will contain an even "power-of-two" number of# elements.
|
||||||
|
# This tells us how many tailing bits each element has# which need to
|
||||||
|
# be truncated to get the group's common prefix.
|
||||||
|
in ((group[0], (len(group) - 1).bit_length()) for group in chunk_index_groups)
|
||||||
|
)
|
||||||
|
return subtree_node_paths
|
||||||
|
|
||||||
|
|
||||||
|
if (
|
||||||
|
# comment1
|
||||||
|
a
|
||||||
|
# comment2
|
||||||
|
or (
|
||||||
|
# comment3
|
||||||
|
(
|
||||||
|
# comment4
|
||||||
|
b
|
||||||
|
)
|
||||||
|
# comment5
|
||||||
|
and
|
||||||
|
# comment6
|
||||||
|
c
|
||||||
|
or (
|
||||||
|
# comment7
|
||||||
|
d
|
||||||
|
)
|
||||||
|
)
|
||||||
|
):
|
||||||
|
print("Foo")
|
|
@ -14,6 +14,6 @@ def function(a:int=42):
|
||||||
a
|
a
|
||||||
b
|
b
|
||||||
"""
|
"""
|
||||||
# There's a NBSP + 3 spaces before
|
# There's a NBSP + 3 spaces before
|
||||||
# And 4 spaces on the next line
|
# And 4 spaces on the next line
|
||||||
pass
|
pass
|
|
@ -0,0 +1 @@
|
||||||
|
{"preview": "enabled"}
|
67
crates/ruff_python_formatter/resources/test/fixtures/black/cases/conditional_expression.py
vendored
Normal file
67
crates/ruff_python_formatter/resources/test/fixtures/black/cases/conditional_expression.py
vendored
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
long_kwargs_single_line = my_function(
|
||||||
|
foo="test, this is a sample value",
|
||||||
|
bar=some_long_value_name_foo_bar_baz if some_boolean_variable else some_fallback_value_foo_bar_baz,
|
||||||
|
baz="hello, this is a another value",
|
||||||
|
)
|
||||||
|
|
||||||
|
multiline_kwargs_indented = my_function(
|
||||||
|
foo="test, this is a sample value",
|
||||||
|
bar=some_long_value_name_foo_bar_baz
|
||||||
|
if some_boolean_variable
|
||||||
|
else some_fallback_value_foo_bar_baz,
|
||||||
|
baz="hello, this is a another value",
|
||||||
|
)
|
||||||
|
|
||||||
|
imploding_kwargs = my_function(
|
||||||
|
foo="test, this is a sample value",
|
||||||
|
bar=a
|
||||||
|
if foo
|
||||||
|
else b,
|
||||||
|
baz="hello, this is a another value",
|
||||||
|
)
|
||||||
|
|
||||||
|
imploding_line = (
|
||||||
|
1
|
||||||
|
if 1 + 1 == 2
|
||||||
|
else 0
|
||||||
|
)
|
||||||
|
|
||||||
|
exploding_line = "hello this is a slightly long string" if some_long_value_name_foo_bar_baz else "this one is a little shorter"
|
||||||
|
|
||||||
|
positional_argument_test(some_long_value_name_foo_bar_baz if some_boolean_variable else some_fallback_value_foo_bar_baz)
|
||||||
|
|
||||||
|
def weird_default_argument(x=some_long_value_name_foo_bar_baz
|
||||||
|
if SOME_CONSTANT
|
||||||
|
else some_fallback_value_foo_bar_baz):
|
||||||
|
pass
|
||||||
|
|
||||||
|
nested = "hello this is a slightly long string" if (some_long_value_name_foo_bar_baz if
|
||||||
|
nesting_test_expressions else some_fallback_value_foo_bar_baz) \
|
||||||
|
else "this one is a little shorter"
|
||||||
|
|
||||||
|
generator_expression = (
|
||||||
|
some_long_value_name_foo_bar_baz if some_boolean_variable else some_fallback_value_foo_bar_baz for some_boolean_variable in some_iterable
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def limit_offset_sql(self, low_mark, high_mark):
|
||||||
|
"""Return LIMIT/OFFSET SQL clause."""
|
||||||
|
limit, offset = self._get_limit_offset_params(low_mark, high_mark)
|
||||||
|
return " ".join(
|
||||||
|
sql
|
||||||
|
for sql in (
|
||||||
|
"LIMIT %d" % limit if limit else None,
|
||||||
|
("OFFSET %d" % offset) if offset else None,
|
||||||
|
)
|
||||||
|
if sql
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def something():
|
||||||
|
clone._iterable_class = (
|
||||||
|
NamedValuesListIterable
|
||||||
|
if named
|
||||||
|
else FlatValuesListIterable
|
||||||
|
if flat
|
||||||
|
else ValuesListIterable
|
||||||
|
)
|
|
@ -0,0 +1,90 @@
|
||||||
|
long_kwargs_single_line = my_function(
|
||||||
|
foo="test, this is a sample value",
|
||||||
|
bar=(
|
||||||
|
some_long_value_name_foo_bar_baz
|
||||||
|
if some_boolean_variable
|
||||||
|
else some_fallback_value_foo_bar_baz
|
||||||
|
),
|
||||||
|
baz="hello, this is a another value",
|
||||||
|
)
|
||||||
|
|
||||||
|
multiline_kwargs_indented = my_function(
|
||||||
|
foo="test, this is a sample value",
|
||||||
|
bar=(
|
||||||
|
some_long_value_name_foo_bar_baz
|
||||||
|
if some_boolean_variable
|
||||||
|
else some_fallback_value_foo_bar_baz
|
||||||
|
),
|
||||||
|
baz="hello, this is a another value",
|
||||||
|
)
|
||||||
|
|
||||||
|
imploding_kwargs = my_function(
|
||||||
|
foo="test, this is a sample value",
|
||||||
|
bar=a if foo else b,
|
||||||
|
baz="hello, this is a another value",
|
||||||
|
)
|
||||||
|
|
||||||
|
imploding_line = 1 if 1 + 1 == 2 else 0
|
||||||
|
|
||||||
|
exploding_line = (
|
||||||
|
"hello this is a slightly long string"
|
||||||
|
if some_long_value_name_foo_bar_baz
|
||||||
|
else "this one is a little shorter"
|
||||||
|
)
|
||||||
|
|
||||||
|
positional_argument_test(
|
||||||
|
some_long_value_name_foo_bar_baz
|
||||||
|
if some_boolean_variable
|
||||||
|
else some_fallback_value_foo_bar_baz
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def weird_default_argument(
|
||||||
|
x=(
|
||||||
|
some_long_value_name_foo_bar_baz
|
||||||
|
if SOME_CONSTANT
|
||||||
|
else some_fallback_value_foo_bar_baz
|
||||||
|
),
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
nested = (
|
||||||
|
"hello this is a slightly long string"
|
||||||
|
if (
|
||||||
|
some_long_value_name_foo_bar_baz
|
||||||
|
if nesting_test_expressions
|
||||||
|
else some_fallback_value_foo_bar_baz
|
||||||
|
)
|
||||||
|
else "this one is a little shorter"
|
||||||
|
)
|
||||||
|
|
||||||
|
generator_expression = (
|
||||||
|
(
|
||||||
|
some_long_value_name_foo_bar_baz
|
||||||
|
if some_boolean_variable
|
||||||
|
else some_fallback_value_foo_bar_baz
|
||||||
|
)
|
||||||
|
for some_boolean_variable in some_iterable
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def limit_offset_sql(self, low_mark, high_mark):
|
||||||
|
"""Return LIMIT/OFFSET SQL clause."""
|
||||||
|
limit, offset = self._get_limit_offset_params(low_mark, high_mark)
|
||||||
|
return " ".join(
|
||||||
|
sql
|
||||||
|
for sql in (
|
||||||
|
"LIMIT %d" % limit if limit else None,
|
||||||
|
("OFFSET %d" % offset) if offset else None,
|
||||||
|
)
|
||||||
|
if sql
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def something():
|
||||||
|
clone._iterable_class = (
|
||||||
|
NamedValuesListIterable
|
||||||
|
if named
|
||||||
|
else FlatValuesListIterable if flat else ValuesListIterable
|
||||||
|
)
|
|
@ -219,3 +219,10 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||||
|
|
||||||
<text here, since without another non-empty line black is stable>
|
<text here, since without another non-empty line black is stable>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
def foo():
|
||||||
|
"""
|
||||||
|
Docstring with a backslash followed by a space\
|
||||||
|
and then another line
|
||||||
|
"""
|
|
@ -217,3 +217,10 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||||
|
|
||||||
<text here, since without another non-empty line black is stable>
|
<text here, since without another non-empty line black is stable>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def foo():
|
||||||
|
"""
|
||||||
|
Docstring with a backslash followed by a space\
|
||||||
|
and then another line
|
||||||
|
"""
|
|
@ -3,7 +3,8 @@ def docstring_almost_at_line_limit():
|
||||||
|
|
||||||
|
|
||||||
def docstring_almost_at_line_limit_with_prefix():
|
def docstring_almost_at_line_limit_with_prefix():
|
||||||
f"""long docstring................................................................"""
|
f"""long docstring................................................................
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def mulitline_docstring_almost_at_line_limit():
|
def mulitline_docstring_almost_at_line_limit():
|
8
crates/ruff_python_formatter/resources/test/fixtures/black/cases/f_docstring.py
vendored
Normal file
8
crates/ruff_python_formatter/resources/test/fixtures/black/cases/f_docstring.py
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
def foo(e):
|
||||||
|
f""" {'.'.join(e)}"""
|
||||||
|
|
||||||
|
def bar(e):
|
||||||
|
f"{'.'.join(e)}"
|
||||||
|
|
||||||
|
def baz(e):
|
||||||
|
F""" {'.'.join(e)}"""
|
10
crates/ruff_python_formatter/resources/test/fixtures/black/cases/f_docstring.py.expect
vendored
Normal file
10
crates/ruff_python_formatter/resources/test/fixtures/black/cases/f_docstring.py.expect
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
def foo(e):
|
||||||
|
f""" {'.'.join(e)}"""
|
||||||
|
|
||||||
|
|
||||||
|
def bar(e):
|
||||||
|
f"{'.'.join(e)}"
|
||||||
|
|
||||||
|
|
||||||
|
def baz(e):
|
||||||
|
f""" {'.'.join(e)}"""
|
|
@ -0,0 +1 @@
|
||||||
|
{"preview": "enabled"}
|
|
@ -0,0 +1,143 @@
|
||||||
|
# normal, short, function definition
|
||||||
|
def foo(a, b) -> tuple[int, float]: ...
|
||||||
|
|
||||||
|
|
||||||
|
# normal, short, function definition w/o return type
|
||||||
|
def foo(a, b): ...
|
||||||
|
|
||||||
|
|
||||||
|
# no splitting
|
||||||
|
def foo(a: A, b: B) -> list[p, q]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# magic trailing comma in param list
|
||||||
|
def foo(a, b,): ...
|
||||||
|
|
||||||
|
|
||||||
|
# magic trailing comma in nested params in param list
|
||||||
|
def foo(a, b: tuple[int, float,]): ...
|
||||||
|
|
||||||
|
|
||||||
|
# magic trailing comma in return type, no params
|
||||||
|
def a() -> tuple[
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
]: ...
|
||||||
|
|
||||||
|
|
||||||
|
# magic trailing comma in return type, params
|
||||||
|
def foo(a: A, b: B) -> list[
|
||||||
|
p,
|
||||||
|
q,
|
||||||
|
]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# magic trailing comma in param list and in return type
|
||||||
|
def foo(
|
||||||
|
a: a,
|
||||||
|
b: b,
|
||||||
|
) -> list[
|
||||||
|
a,
|
||||||
|
a,
|
||||||
|
]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# long function definition, param list is longer
|
||||||
|
def aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
|
||||||
|
bbbbbbbbbbbbbbbbbb,
|
||||||
|
) -> cccccccccccccccccccccccccccccc: ...
|
||||||
|
|
||||||
|
|
||||||
|
# long function definition, return type is longer
|
||||||
|
# this should maybe split on rhs?
|
||||||
|
def aaaaaaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbb) -> list[
|
||||||
|
Ccccccccccccccccccccccccccccccccccccccccccccccccccc, Dddddd
|
||||||
|
]: ...
|
||||||
|
|
||||||
|
|
||||||
|
# long return type, no param list
|
||||||
|
def foo() -> list[
|
||||||
|
Loooooooooooooooooooooooooooooooooooong,
|
||||||
|
Loooooooooooooooooooong,
|
||||||
|
Looooooooooooong,
|
||||||
|
]: ...
|
||||||
|
|
||||||
|
|
||||||
|
# long function name, no param list, no return value
|
||||||
|
def thiiiiiiiiiiiiiiiiiis_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiis_veeeeeeeeeeeeeeeeeeeeeeery_looooooong():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# long function name, no param list
|
||||||
|
def thiiiiiiiiiiiiiiiiiis_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiis_veeeeeeeeeeeeeeeeeeeeeeery_looooooong() -> (
|
||||||
|
list[int, float]
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
# long function name, no return value
|
||||||
|
def thiiiiiiiiiiiiiiiiiis_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiis_veeeeeeeeeeeeeeeeeeeeeeery_looooooong(
|
||||||
|
a, b
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
# unskippable type hint (??)
|
||||||
|
def foo(a) -> list[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]: # type: ignore
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def foo(a) -> list[
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
]: # abpedeifnore
|
||||||
|
pass
|
||||||
|
|
||||||
|
def foo(a, b: list[Bad],): ... # type: ignore
|
||||||
|
|
||||||
|
# don't lose any comments (no magic)
|
||||||
|
def foo( # 1
|
||||||
|
a, # 2
|
||||||
|
b) -> list[ # 3
|
||||||
|
a, # 4
|
||||||
|
b]: # 5
|
||||||
|
... # 6
|
||||||
|
|
||||||
|
|
||||||
|
# don't lose any comments (param list magic)
|
||||||
|
def foo( # 1
|
||||||
|
a, # 2
|
||||||
|
b,) -> list[ # 3
|
||||||
|
a, # 4
|
||||||
|
b]: # 5
|
||||||
|
... # 6
|
||||||
|
|
||||||
|
|
||||||
|
# don't lose any comments (return type magic)
|
||||||
|
def foo( # 1
|
||||||
|
a, # 2
|
||||||
|
b) -> list[ # 3
|
||||||
|
a, # 4
|
||||||
|
b,]: # 5
|
||||||
|
... # 6
|
||||||
|
|
||||||
|
|
||||||
|
# don't lose any comments (both magic)
|
||||||
|
def foo( # 1
|
||||||
|
a, # 2
|
||||||
|
b,) -> list[ # 3
|
||||||
|
a, # 4
|
||||||
|
b,]: # 5
|
||||||
|
... # 6
|
||||||
|
|
||||||
|
# real life example
|
||||||
|
def SimplePyFn(
|
||||||
|
context: hl.GeneratorContext,
|
||||||
|
buffer_input: Buffer[UInt8, 2],
|
||||||
|
func_input: Buffer[Int32, 2],
|
||||||
|
float_arg: Scalar[Float32],
|
||||||
|
offset: int = 0,
|
||||||
|
) -> tuple[
|
||||||
|
Buffer[UInt8, 2],
|
||||||
|
Buffer[UInt8, 2],
|
||||||
|
]: ...
|
|
@ -0,0 +1,156 @@
|
||||||
|
# normal, short, function definition
|
||||||
|
def foo(a, b) -> tuple[int, float]: ...
|
||||||
|
|
||||||
|
|
||||||
|
# normal, short, function definition w/o return type
|
||||||
|
def foo(a, b): ...
|
||||||
|
|
||||||
|
|
||||||
|
# no splitting
|
||||||
|
def foo(a: A, b: B) -> list[p, q]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# magic trailing comma in param list
|
||||||
|
def foo(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
# magic trailing comma in nested params in param list
|
||||||
|
def foo(
|
||||||
|
a,
|
||||||
|
b: tuple[
|
||||||
|
int,
|
||||||
|
float,
|
||||||
|
],
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
# magic trailing comma in return type, no params
|
||||||
|
def a() -> tuple[
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
]: ...
|
||||||
|
|
||||||
|
|
||||||
|
# magic trailing comma in return type, params
|
||||||
|
def foo(a: A, b: B) -> list[
|
||||||
|
p,
|
||||||
|
q,
|
||||||
|
]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# magic trailing comma in param list and in return type
|
||||||
|
def foo(
|
||||||
|
a: a,
|
||||||
|
b: b,
|
||||||
|
) -> list[
|
||||||
|
a,
|
||||||
|
a,
|
||||||
|
]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# long function definition, param list is longer
|
||||||
|
def aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
|
||||||
|
bbbbbbbbbbbbbbbbbb,
|
||||||
|
) -> cccccccccccccccccccccccccccccc: ...
|
||||||
|
|
||||||
|
|
||||||
|
# long function definition, return type is longer
|
||||||
|
# this should maybe split on rhs?
|
||||||
|
def aaaaaaaaaaaaaaaaa(
|
||||||
|
bbbbbbbbbbbbbbbbbb,
|
||||||
|
) -> list[Ccccccccccccccccccccccccccccccccccccccccccccccccccc, Dddddd]: ...
|
||||||
|
|
||||||
|
|
||||||
|
# long return type, no param list
|
||||||
|
def foo() -> list[
|
||||||
|
Loooooooooooooooooooooooooooooooooooong,
|
||||||
|
Loooooooooooooooooooong,
|
||||||
|
Looooooooooooong,
|
||||||
|
]: ...
|
||||||
|
|
||||||
|
|
||||||
|
# long function name, no param list, no return value
|
||||||
|
def thiiiiiiiiiiiiiiiiiis_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiis_veeeeeeeeeeeeeeeeeeeeeeery_looooooong():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# long function name, no param list
|
||||||
|
def thiiiiiiiiiiiiiiiiiis_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiis_veeeeeeeeeeeeeeeeeeeeeeery_looooooong() -> (
|
||||||
|
list[int, float]
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
# long function name, no return value
|
||||||
|
def thiiiiiiiiiiiiiiiiiis_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiis_veeeeeeeeeeeeeeeeeeeeeeery_looooooong(
|
||||||
|
a, b
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
# unskippable type hint (??)
|
||||||
|
def foo(a) -> list[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]: # type: ignore
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def foo(
|
||||||
|
a,
|
||||||
|
) -> list[
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
]: # abpedeifnore
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def foo(
|
||||||
|
a,
|
||||||
|
b: list[Bad],
|
||||||
|
): ... # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
# don't lose any comments (no magic)
|
||||||
|
def foo(a, b) -> list[a, b]: # 1 # 2 # 3 # 4 # 5
|
||||||
|
... # 6
|
||||||
|
|
||||||
|
|
||||||
|
# don't lose any comments (param list magic)
|
||||||
|
def foo( # 1
|
||||||
|
a, # 2
|
||||||
|
b,
|
||||||
|
) -> list[a, b]: # 3 # 4 # 5
|
||||||
|
... # 6
|
||||||
|
|
||||||
|
|
||||||
|
# don't lose any comments (return type magic)
|
||||||
|
def foo(a, b) -> list[ # 1 # 2 # 3
|
||||||
|
a, # 4
|
||||||
|
b,
|
||||||
|
]: # 5
|
||||||
|
... # 6
|
||||||
|
|
||||||
|
|
||||||
|
# don't lose any comments (both magic)
|
||||||
|
def foo( # 1
|
||||||
|
a, # 2
|
||||||
|
b,
|
||||||
|
) -> list[ # 3
|
||||||
|
a, # 4
|
||||||
|
b,
|
||||||
|
]: # 5
|
||||||
|
... # 6
|
||||||
|
|
||||||
|
|
||||||
|
# real life example
|
||||||
|
def SimplePyFn(
|
||||||
|
context: hl.GeneratorContext,
|
||||||
|
buffer_input: Buffer[UInt8, 2],
|
||||||
|
func_input: Buffer[Int32, 2],
|
||||||
|
float_arg: Scalar[Float32],
|
||||||
|
offset: int = 0,
|
||||||
|
) -> tuple[
|
||||||
|
Buffer[UInt8, 2],
|
||||||
|
Buffer[UInt8, 2],
|
||||||
|
]: ...
|
|
@ -15,6 +15,7 @@ def g():
|
||||||
# hi
|
# hi
|
||||||
...
|
...
|
||||||
|
|
||||||
def h():
|
# FIXME(#8905): Uncomment, leads to unstable formatting
|
||||||
...
|
# def h():
|
||||||
# bye
|
# ...
|
||||||
|
# # bye
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue