--- source: crates/ruff_python_formatter/tests/fixtures.rs input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments6.py --- ## Input ```py from typing import Any, Tuple def f( a, # type: int ): pass # test type comments def f(a, b, c, d, e, f, g, h, i): # type: (int, int, int, int, int, int, int, int, int) -> None pass def f( a, # type: int b, # type: int c, # type: int d, # type: int e, # type: int f, # type: int g, # type: int h, # type: int i, # type: int ): # type: (...) -> None pass def f( arg, # type: int *args, # type: *Any default=False, # type: bool **kwargs, # type: **Any ): # type: (...) -> None pass def f( a, # type: int b, # type: int c, # type: int d, # type: int ): # type: (...) -> None element = 0 # type: int another_element = 1 # type: float another_element_with_long_name = 2 # type: int another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = ( 3 ) # type: int an_element_with_a_long_value = calls() or more_calls() and more() # type: bool tup = ( another_element, another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style, ) # type: Tuple[int, int] a = ( element + another_element + another_element_with_long_name + element + another_element + another_element_with_long_name ) # type: int def f( x, # not a type comment y, # type: int ): # type: (...) -> None pass def f( x, # not a type comment ): # type: (int) -> None pass def func( a=some_list[0], # type: int ): # type: () -> int c = call( 0.0123, 0.0456, 0.0789, 0.0123, 0.0456, 0.0789, 0.0123, 0.0456, 0.0789, a[-1], # type: ignore ) c = call( "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore ) result = ( # aaa "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ) AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore call_to_some_function_asdf( foo, [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore ) aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] ``` ## Black Differences ```diff --- Black +++ Ruff @@ -1,4 +1,4 @@ -from typing import Any, Tuple +NOT_YET_IMPLEMENTED_StmtImportFrom def f( @@ -49,10 +49,11 @@ element = 0 # type: int another_element = 1 # type: float another_element_with_long_name = 2 # type: int - another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = ( - 3 - ) # type: int - an_element_with_a_long_value = calls() or more_calls() and more() # type: bool + another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = 3 # type: int + an_element_with_a_long_value = ( + NOT_IMPLEMENTED_call() + or NOT_IMPLEMENTED_call() and NOT_IMPLEMENTED_call() + ) # type: bool tup = ( another_element, @@ -86,33 +87,20 @@ def func( a=some_list[0], # type: int ): # type: () -> int - c = call( - 0.0123, - 0.0456, - 0.0789, - 0.0123, - 0.0456, - 0.0789, - 0.0123, - 0.0456, - 0.0789, - a[-1], # type: ignore - ) + c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) - c = call( - "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore - ) + c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) -result = ( # aaa - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -) +result = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # aaa -AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore +AAAAAAAAAAAAA = ( + [AAAAAAAAAAAAA] + + SHARED_AAAAAAAAAAAAA + + USER_AAAAAAAAAAAAA + + AAAAAAAAAAAAA +) # type: ignore -call_to_some_function_asdf( - foo, - [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore -) +NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) -aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] +aaaaaaaaaaaaa, bbbbbbbbb = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # type: ignore[arg-type] ``` ## Ruff Output ```py NOT_YET_IMPLEMENTED_StmtImportFrom def f( a, # type: int ): pass # test type comments def f(a, b, c, d, e, f, g, h, i): # type: (int, int, int, int, int, int, int, int, int) -> None pass def f( a, # type: int b, # type: int c, # type: int d, # type: int e, # type: int f, # type: int g, # type: int h, # type: int i, # type: int ): # type: (...) -> None pass def f( arg, # type: int *args, # type: *Any default=False, # type: bool **kwargs, # type: **Any ): # type: (...) -> None pass def f( a, # type: int b, # type: int c, # type: int d, # type: int ): # type: (...) -> None element = 0 # type: int another_element = 1 # type: float another_element_with_long_name = 2 # type: int another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = 3 # type: int an_element_with_a_long_value = ( NOT_IMPLEMENTED_call() or NOT_IMPLEMENTED_call() and NOT_IMPLEMENTED_call() ) # type: bool tup = ( another_element, another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style, ) # type: Tuple[int, int] a = ( element + another_element + another_element_with_long_name + element + another_element + another_element_with_long_name ) # type: int def f( x, # not a type comment y, # type: int ): # type: (...) -> None pass def f( x, # not a type comment ): # type: (int) -> None pass def func( a=some_list[0], # type: int ): # type: () -> int c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) result = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # aaa AAAAAAAAAAAAA = ( [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA ) # type: ignore NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) aaaaaaaaaaaaa, bbbbbbbbb = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # type: ignore[arg-type] ``` ## Black Output ```py from typing import Any, Tuple def f( a, # type: int ): pass # test type comments def f(a, b, c, d, e, f, g, h, i): # type: (int, int, int, int, int, int, int, int, int) -> None pass def f( a, # type: int b, # type: int c, # type: int d, # type: int e, # type: int f, # type: int g, # type: int h, # type: int i, # type: int ): # type: (...) -> None pass def f( arg, # type: int *args, # type: *Any default=False, # type: bool **kwargs, # type: **Any ): # type: (...) -> None pass def f( a, # type: int b, # type: int c, # type: int d, # type: int ): # type: (...) -> None element = 0 # type: int another_element = 1 # type: float another_element_with_long_name = 2 # type: int another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = ( 3 ) # type: int an_element_with_a_long_value = calls() or more_calls() and more() # type: bool tup = ( another_element, another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style, ) # type: Tuple[int, int] a = ( element + another_element + another_element_with_long_name + element + another_element + another_element_with_long_name ) # type: int def f( x, # not a type comment y, # type: int ): # type: (...) -> None pass def f( x, # not a type comment ): # type: (int) -> None pass def func( a=some_list[0], # type: int ): # type: () -> int c = call( 0.0123, 0.0456, 0.0789, 0.0123, 0.0456, 0.0789, 0.0123, 0.0456, 0.0789, a[-1], # type: ignore ) c = call( "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore ) result = ( # aaa "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ) AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore call_to_some_function_asdf( foo, [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore ) aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] ```