From 21a4f75689186add54f04ab3749ac1c664a9c6d7 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 10 Jan 2024 13:03:39 +0100 Subject: [PATCH] Update Black Tests --- .../cases/class_blank_parentheses.py.expect | 1 + .../black/cases/conditional_expression.py | 22 +++ .../cases/conditional_expression.py.expect | 20 +++ .../fixtures/black/cases/line_ranges_basic.py | 2 +- .../black/cases/line_ranges_basic.py.expect | 2 +- .../black/cases/module_docstring_2.py | 1 + .../black/cases/module_docstring_2.py.expect | 1 + .../test/fixtures/black/cases/nested_stub.pyi | 12 ++ .../black/cases/nested_stub.pyi.expect | 13 ++ .../cases/pep604_union_types_line_breaks.py | 2 +- .../pep604_union_types_line_breaks.py.expect | 2 +- .../cases/preview_allow_empty_first_line.py | 20 +++ .../preview_allow_empty_first_line.py.expect | 19 +++ .../cases/preview_dummy_implementations.py | 11 ++ .../preview_dummy_implementations.py.expect | 11 ++ .../black/cases/preview_form_feeds.py.expect | 1 + .../preview_no_blank_line_before_docstring.py | 4 + ...w_no_blank_line_before_docstring.py.expect | 4 + .../black/cases/preview_pep_572.py.expect | 4 +- ...ity@cases__class_blank_parentheses.py.snap | 119 ++++++++++++++++ ...lity@cases__conditional_expression.py.snap | 66 ++++++++- ...atibility@cases__line_ranges_basic.py.snap | 8 +- ...tibility@cases__module_docstring_2.py.snap | 133 ++++++++++++++++++ ..._compatibility@cases__nested_stub.pyi.snap | 59 +++++++- ...es__pep604_union_types_line_breaks.py.snap | 6 +- ...es__preview_allow_empty_first_line.py.snap | 68 ++++++++- ...tibility@cases__preview_form_feeds.py.snap | 9 +- ...mpatibility@cases__preview_pep_572.py.snap | 38 ----- 28 files changed, 602 insertions(+), 56 deletions(-) create mode 100644 crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__class_blank_parentheses.py.snap create mode 100644 crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__module_docstring_2.py.snap delete mode 100644 crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_pep_572.py.snap diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/class_blank_parentheses.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/class_blank_parentheses.py.expect index 0c4c3c96e7f72..5745e520d40e4 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/class_blank_parentheses.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/class_blank_parentheses.py.expect @@ -11,6 +11,7 @@ class ClassWithSpaceParentheses: class ClassWithEmptyFunc(object): + def func_with_blank_parentheses(): return 5 diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/conditional_expression.py b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/conditional_expression.py index bbe56623c6107..8ce364fb22058 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/conditional_expression.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/conditional_expression.py @@ -65,3 +65,25 @@ def something(): if flat else ValuesListIterable ) + + +def foo(wait: bool = True): + # This comment is two + # lines long + + # This is only one + time.sleep(1) if wait else None + time.sleep(1) if wait else None + + # With newline above + time.sleep(1) if wait else None + # Without newline above + time.sleep(1) if wait else None + + +a = "".join( + ( + "", # comment + "" if True else "", + ) +) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/conditional_expression.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/conditional_expression.py.expect index 122ea7860dea7..0d80042ca145b 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/conditional_expression.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/conditional_expression.py.expect @@ -88,3 +88,23 @@ def something(): if named else FlatValuesListIterable if flat else ValuesListIterable ) + + +def foo(wait: bool = True): + # This comment is two + # lines long + + # This is only one + time.sleep(1) if wait else None + time.sleep(1) if wait else None + + # With newline above + time.sleep(1) if wait else None + # Without newline above + time.sleep(1) if wait else None + + +a = "".join(( + "", # comment + "" if True else "", +)) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/line_ranges_basic.py b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/line_ranges_basic.py index 31d762c397790..40d0f7053b9e2 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/line_ranges_basic.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/line_ranges_basic.py @@ -5,7 +5,7 @@ def foo2(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parame def foo3(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass -# Adding some unformatted code covering a wide range of syntaxes. +# Adding some unformated code covering a wide range of syntaxes. if True: # Incorrectly indented prefix comments. diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/line_ranges_basic.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/line_ranges_basic.py.expect index 01c9c002e3264..7fdfdfd0dbbae 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/line_ranges_basic.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/line_ranges_basic.py.expect @@ -28,7 +28,7 @@ def foo3( def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass -# Adding some unformatted code covering a wide range of syntaxes. +# Adding some unformated code covering a wide range of syntaxes. if True: # Incorrectly indented prefix comments. diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/module_docstring_2.py b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/module_docstring_2.py index 48be31c41c906..724e28cd4ebac 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/module_docstring_2.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/module_docstring_2.py @@ -1,5 +1,6 @@ """I am a very helpful module docstring. +With trailing spaces: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/module_docstring_2.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/module_docstring_2.py.expect index 6c07d2d16978e..9b270c521b34b 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/module_docstring_2.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/module_docstring_2.py.expect @@ -1,5 +1,6 @@ """I am a very helpful module docstring. +With trailing spaces: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/nested_stub.pyi b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/nested_stub.pyi index 2cb19a8ba0dd6..0751434f63f30 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/nested_stub.pyi +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/nested_stub.pyi @@ -16,3 +16,15 @@ if sys.version_info > (3, 7): def function_definition(self): ... assignment = 1 def f2(self) -> str: ... + + +class TopLevel: + class Nested1: + foo: int + def bar(self): ... + field = 1 + + class Nested2: + def bar(self): ... + foo: int + field = 1 diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/nested_stub.pyi.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/nested_stub.pyi.expect index da431eb8493f1..1af122806e40d 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/nested_stub.pyi.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/nested_stub.pyi.expect @@ -20,3 +20,16 @@ if sys.version_info > (3, 7): assignment = 1 def f2(self) -> str: ... + +class TopLevel: + class Nested1: + foo: int + def bar(self): ... + + field = 1 + + class Nested2: + def bar(self): ... + foo: int + + field = 1 diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep604_union_types_line_breaks.py b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep604_union_types_line_breaks.py index 930759735bdc7..bd3e48417b6b5 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep604_union_types_line_breaks.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep604_union_types_line_breaks.py @@ -19,7 +19,7 @@ z: (int) = 2.3 z: ((int)) = foo() -# In case I go for not enforcing parentheses, this might get improved at the same time +# In case I go for not enforcing parantheses, this might get improved at the same time x = ( z == 9999999999999999999999999999999999999999 diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep604_union_types_line_breaks.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep604_union_types_line_breaks.py.expect index e9c2f75f7e748..ab0a4d96772ca 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep604_union_types_line_breaks.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep604_union_types_line_breaks.py.expect @@ -28,7 +28,7 @@ z: Short | Short2 | Short3 | Short4 = 8 z: int = 2.3 z: int = foo() -# In case I go for not enforcing parentheses, this might get improved at the same time +# In case I go for not enforcing parantheses, this might get improved at the same time x = ( z == 9999999999999999999999999999999999999999 diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_allow_empty_first_line.py b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_allow_empty_first_line.py index 72d6310be1127..44b54ba9d7aa5 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_allow_empty_first_line.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_allow_empty_first_line.py @@ -60,3 +60,23 @@ class Cls: def method(self): pass + + +async def async_fn(): + + """Docstring.""" + + +@decorated +async def async_fn(): + + """Docstring.""" + + +def top_level( + a: int, + b: str, +) -> Whatever[Generic, Something]: + + def nested(x: int) -> int: + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_allow_empty_first_line.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_allow_empty_first_line.py.expect index 08c37d3ffabe2..3e5bdea0f93e5 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_allow_empty_first_line.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_allow_empty_first_line.py.expect @@ -57,6 +57,25 @@ def quux(): class Cls: + def method(self): pass + + +async def async_fn(): + """Docstring.""" + + +@decorated +async def async_fn(): + """Docstring.""" + + +def top_level( + a: int, + b: str, +) -> Whatever[Generic, Something]: + + def nested(x: int) -> int: + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_dummy_implementations.py b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_dummy_implementations.py index e7e6f6e421143..739359ee25bbc 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_dummy_implementations.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_dummy_implementations.py @@ -56,3 +56,14 @@ def has_comment(): ... if already_dummy: ... + +class AsyncCls: + async def async_method(self): + ... + +async def async_function(self): + ... + +@decorated +async def async_function(self): + ... diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_dummy_implementations.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_dummy_implementations.py.expect index f1c2eb9dfb029..369e442152116 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_dummy_implementations.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_dummy_implementations.py.expect @@ -59,3 +59,14 @@ if some_condition: if already_dummy: ... + + +class AsyncCls: + async def async_method(self): ... + + +async def async_function(self): ... + + +@decorated +async def async_function(self): ... diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_form_feeds.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_form_feeds.py.expect index 0a7ab08be41c6..4ce3d2832bf84 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_form_feeds.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_form_feeds.py.expect @@ -79,6 +79,7 @@ def bar(a=1, b: bool = False): class Baz: + def __init__(self): pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_no_blank_line_before_docstring.py b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_no_blank_line_before_docstring.py index 43ba2bd20233a..56d361087d206 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_no_blank_line_before_docstring.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_no_blank_line_before_docstring.py @@ -27,3 +27,7 @@ class MultilineDocstringsAsWell: and on so many lines... """ + +class SingleQuotedDocstring: + + "I'm a docstring but I don't even get triple quotes." diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_no_blank_line_before_docstring.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_no_blank_line_before_docstring.py.expect index 78604d9c9247a..fa042f49338ff 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_no_blank_line_before_docstring.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_no_blank_line_before_docstring.py.expect @@ -22,3 +22,7 @@ class MultilineDocstringsAsWell: and on so many lines... """ + + +class SingleQuotedDocstring: + "I'm a docstring but I don't even get triple quotes." diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_pep_572.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_pep_572.py.expect index 0ae5b9769d12c..a976b8a318bbb 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_pep_572.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_pep_572.py.expect @@ -1,2 +1,2 @@ -x[(a := 0):] -x[:(a := 0)] +x[(a := 0) :] +x[: (a := 0)] diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__class_blank_parentheses.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__class_blank_parentheses.py.snap new file mode 100644 index 0000000000000..2ad0c329cfbef --- /dev/null +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__class_blank_parentheses.py.snap @@ -0,0 +1,119 @@ +--- +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/class_blank_parentheses.py +--- +## Input + +```python +class SimpleClassWithBlankParentheses(): + pass +class ClassWithSpaceParentheses ( ): + first_test_data = 90 + second_test_data = 100 + def test_func(self): + return None +class ClassWithEmptyFunc(object): + + def func_with_blank_parentheses(): + return 5 + + +def public_func_with_blank_parentheses(): + return None +def class_under_the_func_with_blank_parentheses(): + class InsideFunc(): + pass +class NormalClass ( +): + def func_for_testing(self, first, second): + sum = first + second + return sum +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -11,7 +11,6 @@ + + + class ClassWithEmptyFunc(object): +- + def func_with_blank_parentheses(): + return 5 + +``` + +## Ruff Output + +```python +class SimpleClassWithBlankParentheses: + pass + + +class ClassWithSpaceParentheses: + first_test_data = 90 + second_test_data = 100 + + def test_func(self): + return None + + +class ClassWithEmptyFunc(object): + def func_with_blank_parentheses(): + return 5 + + +def public_func_with_blank_parentheses(): + return None + + +def class_under_the_func_with_blank_parentheses(): + class InsideFunc: + pass + + +class NormalClass: + def func_for_testing(self, first, second): + sum = first + second + return sum +``` + +## Black Output + +```python +class SimpleClassWithBlankParentheses: + pass + + +class ClassWithSpaceParentheses: + first_test_data = 90 + second_test_data = 100 + + def test_func(self): + return None + + +class ClassWithEmptyFunc(object): + + def func_with_blank_parentheses(): + return 5 + + +def public_func_with_blank_parentheses(): + return None + + +def class_under_the_func_with_blank_parentheses(): + class InsideFunc: + pass + + +class NormalClass: + def func_for_testing(self, first, second): + sum = first + second + return sum +``` + + diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__conditional_expression.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__conditional_expression.py.snap index 55b4f12034c43..603024b05b69e 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__conditional_expression.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__conditional_expression.py.snap @@ -72,6 +72,28 @@ def something(): if flat else ValuesListIterable ) + + +def foo(wait: bool = True): + # This comment is two + # lines long + + # This is only one + time.sleep(1) if wait else None + time.sleep(1) if wait else None + + # With newline above + time.sleep(1) if wait else None + # Without newline above + time.sleep(1) if wait else None + + +a = "".join( + ( + "", # comment + "" if True else "", + ) +) ``` ## Black Differences @@ -136,7 +158,7 @@ def something(): for some_boolean_variable in some_iterable ) -@@ -86,5 +78,7 @@ +@@ -86,7 +78,9 @@ clone._iterable_class = ( NamedValuesListIterable if named @@ -145,6 +167,8 @@ def something(): + if flat + else ValuesListIterable ) + + ``` ## Ruff Output @@ -234,6 +258,26 @@ def something(): if flat else ValuesListIterable ) + + +def foo(wait: bool = True): + # This comment is two + # lines long + + # This is only one + time.sleep(1) if wait else None + time.sleep(1) if wait else None + + # With newline above + time.sleep(1) if wait else None + # Without newline above + time.sleep(1) if wait else None + + +a = "".join(( + "", # comment + "" if True else "", +)) ``` ## Black Output @@ -329,6 +373,26 @@ def something(): if named else FlatValuesListIterable if flat else ValuesListIterable ) + + +def foo(wait: bool = True): + # This comment is two + # lines long + + # This is only one + time.sleep(1) if wait else None + time.sleep(1) if wait else None + + # With newline above + time.sleep(1) if wait else None + # Without newline above + time.sleep(1) if wait else None + + +a = "".join(( + "", # comment + "" if True else "", +)) ``` diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__line_ranges_basic.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__line_ranges_basic.py.snap index 61e22f3d1cf99..a37d5fec5ad81 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__line_ranges_basic.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__line_ranges_basic.py.snap @@ -12,7 +12,7 @@ def foo2(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parame def foo3(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass -# Adding some unformatted code covering a wide range of syntaxes. +# Adding some unformated code covering a wide range of syntaxes. if True: # Incorrectly indented prefix comments. @@ -89,7 +89,7 @@ async def test_async_unformatted( ): # Trailing comment with extra leading + pass + - # Adding some unformatted code covering a wide range of syntaxes. + # Adding some unformated code covering a wide range of syntaxes. if True: - # Incorrectly indented prefix comments. @@ -207,7 +207,7 @@ def foo4( pass -# Adding some unformatted code covering a wide range of syntaxes. +# Adding some unformated code covering a wide range of syntaxes. if True: # Incorrectly indented prefix comments. @@ -279,7 +279,7 @@ def foo3( def foo4(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, parameter_6, parameter_7): pass -# Adding some unformatted code covering a wide range of syntaxes. +# Adding some unformated code covering a wide range of syntaxes. if True: # Incorrectly indented prefix comments. diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__module_docstring_2.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__module_docstring_2.py.snap new file mode 100644 index 0000000000000..29415b12a7af6 --- /dev/null +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__module_docstring_2.py.snap @@ -0,0 +1,133 @@ +--- +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/module_docstring_2.py +--- +## Input + +```python +"""I am a very helpful module docstring. + +With trailing spaces: +Lorem ipsum dolor sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris +nisi ut aliquip ex ea commodo consequat. +Duis aute irure dolor in reprehenderit in voluptate +velit esse cillum dolore eu fugiat nulla pariatur. +Excepteur sint occaecat cupidatat non proident, +sunt in culpa qui officia deserunt mollit anim id est laborum. +""" + + + + +a = 1 + + +"""Look at me I'm a docstring... + +............................................................ +............................................................ +............................................................ +............................................................ +............................................................ +............................................................ +............................................................ +........................................................NOT! +""" + + + + +b = 2 +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -1,6 +1,6 @@ + """I am a very helpful module docstring. + +-With trailing spaces: ++With trailing spaces: + Lorem ipsum dolor sit amet, consectetur adipiscing elit, + sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + Ut enim ad minim veniam, +``` + +## Ruff Output + +```python +"""I am a very helpful module docstring. + +With trailing spaces: +Lorem ipsum dolor sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris +nisi ut aliquip ex ea commodo consequat. +Duis aute irure dolor in reprehenderit in voluptate +velit esse cillum dolore eu fugiat nulla pariatur. +Excepteur sint occaecat cupidatat non proident, +sunt in culpa qui officia deserunt mollit anim id est laborum. +""" + +a = 1 + + +"""Look at me I'm a docstring... + +............................................................ +............................................................ +............................................................ +............................................................ +............................................................ +............................................................ +............................................................ +........................................................NOT! +""" + + +b = 2 +``` + +## Black Output + +```python +"""I am a very helpful module docstring. + +With trailing spaces: +Lorem ipsum dolor sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris +nisi ut aliquip ex ea commodo consequat. +Duis aute irure dolor in reprehenderit in voluptate +velit esse cillum dolore eu fugiat nulla pariatur. +Excepteur sint occaecat cupidatat non proident, +sunt in culpa qui officia deserunt mollit anim id est laborum. +""" + +a = 1 + + +"""Look at me I'm a docstring... + +............................................................ +............................................................ +............................................................ +............................................................ +............................................................ +............................................................ +............................................................ +........................................................NOT! +""" + + +b = 2 +``` + + diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__nested_stub.pyi.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__nested_stub.pyi.snap index 9ebdd53453119..86a725c416964 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__nested_stub.pyi.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__nested_stub.pyi.snap @@ -23,6 +23,18 @@ if sys.version_info > (3, 7): def function_definition(self): ... assignment = 1 def f2(self) -> str: ... + + +class TopLevel: + class Nested1: + foo: int + def bar(self): ... + field = 1 + + class Nested2: + def bar(self): ... + foo: int + field = 1 ``` ## Black Differences @@ -40,7 +52,7 @@ if sys.version_info > (3, 7): outer_attr_after_inner_stub: int class Inner: -@@ -9,14 +11,19 @@ +@@ -9,27 +11,35 @@ outer_attr: int @@ -60,6 +72,22 @@ if sys.version_info > (3, 7): assignment = 1 def f2(self) -> str: ... + ++ + class TopLevel: + class Nested1: + foo: int ++ + def bar(self): ... + + field = 1 + + class Nested2: + def bar(self): ... ++ + foo: int + + field = 1 ``` ## Ruff Output @@ -94,6 +122,22 @@ if sys.version_info > (3, 7): assignment = 1 def f2(self) -> str: ... + + +class TopLevel: + class Nested1: + foo: int + + def bar(self): ... + + field = 1 + + class Nested2: + def bar(self): ... + + foo: int + + field = 1 ``` ## Black Output @@ -121,6 +165,19 @@ if sys.version_info > (3, 7): assignment = 1 def f2(self) -> str: ... + +class TopLevel: + class Nested1: + foo: int + def bar(self): ... + + field = 1 + + class Nested2: + def bar(self): ... + foo: int + + field = 1 ``` diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__pep604_union_types_line_breaks.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__pep604_union_types_line_breaks.py.snap index 28c71d4f3e50d..d84b08e5125c6 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__pep604_union_types_line_breaks.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__pep604_union_types_line_breaks.py.snap @@ -26,7 +26,7 @@ z: (Short z: (int) = 2.3 z: ((int)) = foo() -# In case I go for not enforcing parentheses, this might get improved at the same time +# In case I go for not enforcing parantheses, this might get improved at the same time x = ( z == 9999999999999999999999999999999999999999 @@ -165,7 +165,7 @@ z: Short | Short2 | Short3 | Short4 = 8 z: int = 2.3 z: int = foo() -# In case I go for not enforcing parentheses, this might get improved at the same time +# In case I go for not enforcing parantheses, this might get improved at the same time x = ( z == 9999999999999999999999999999999999999999 @@ -269,7 +269,7 @@ z: Short | Short2 | Short3 | Short4 = 8 z: int = 2.3 z: int = foo() -# In case I go for not enforcing parentheses, this might get improved at the same time +# In case I go for not enforcing parantheses, this might get improved at the same time x = ( z == 9999999999999999999999999999999999999999 diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_allow_empty_first_line.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_allow_empty_first_line.py.snap index 91d79fe14e372..7ff5d6d32d55b 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_allow_empty_first_line.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_allow_empty_first_line.py.snap @@ -67,6 +67,26 @@ class Cls: def method(self): pass + + +async def async_fn(): + + """Docstring.""" + + +@decorated +async def async_fn(): + + """Docstring.""" + + +def top_level( + a: int, + b: str, +) -> Whatever[Generic, Something]: + + def nested(x: int) -> int: + pass ``` ## Black Differences @@ -82,7 +102,7 @@ class Cls: # This is also now fine a = 123 -@@ -14,49 +13,39 @@ +@@ -14,52 +13,41 @@ a = 123 if y: @@ -129,9 +149,19 @@ class Cls: class Cls: +- def method(self): - pass + + +@@ -76,6 +64,5 @@ + a: int, + b: str, + ) -> Whatever[Generic, Something]: +- + def nested(x: int) -> int: + pass ``` ## Ruff Output @@ -188,6 +218,23 @@ def quux(): class Cls: def method(self): pass + + +async def async_fn(): + """Docstring.""" + + +@decorated +async def async_fn(): + """Docstring.""" + + +def top_level( + a: int, + b: str, +) -> Whatever[Generic, Something]: + def nested(x: int) -> int: + pass ``` ## Black Output @@ -252,9 +299,28 @@ def quux(): class Cls: + def method(self): pass + + +async def async_fn(): + """Docstring.""" + + +@decorated +async def async_fn(): + """Docstring.""" + + +def top_level( + a: int, + b: str, +) -> Whatever[Generic, Something]: + + def nested(x: int) -> int: + pass ``` diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_form_feeds.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_form_feeds.py.snap index d12ba4bab7cd4..09b03d396a174 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_form_feeds.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_form_feeds.py.snap @@ -211,7 +211,7 @@ a = [ pass -@@ -68,13 +68,12 @@ +@@ -68,25 +68,23 @@ def foo(): pass @@ -226,7 +226,11 @@ a = [ pass -@@ -85,7 +84,7 @@ + class Baz: +- + def __init__(self): + pass + def something(self): pass @@ -427,6 +431,7 @@ def bar(a=1, b: bool = False): class Baz: + def __init__(self): pass diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_pep_572.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_pep_572.py.snap deleted file mode 100644 index 03f27f16c2f35..0000000000000 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_pep_572.py.snap +++ /dev/null @@ -1,38 +0,0 @@ ---- -source: crates/ruff_python_formatter/tests/fixtures.rs -input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_pep_572.py ---- -## Input - -```python -x[(a:=0):] -x[:(a:=0)] -``` - -## Black Differences - -```diff ---- Black -+++ Ruff -@@ -1,2 +1,2 @@ --x[(a := 0):] --x[:(a := 0)] -+x[(a := 0) :] -+x[: (a := 0)] -``` - -## Ruff Output - -```python -x[(a := 0) :] -x[: (a := 0)] -``` - -## Black Output - -```python -x[(a := 0):] -x[:(a := 0)] -``` - -