black/tests/data/miscellaneous
konsti b40b01ffe3
Blank line between nested and function def in stub files. (#3862)
The idea behind this change is that we stop looking into previous body to determine if there should be a blank before a function or class definition.

Input:

```python
import sys

if sys.version_info > (3, 7):
    class Nested1:
        assignment = 1
        def function_definition(self): ...
    def f1(self) -> str: ...
    class Nested2:
        def function_definition(self): ...
        assignment = 1
    def f2(self) -> str: ...

if sys.version_info > (3, 7):
    def nested1():
        assignment = 1
        def function_definition(self): ...
    def f1(self) -> str: ...
    def nested2():
        def function_definition(self): ...
        assignment = 1
    def f2(self) -> str: ...
```

Stable style
```python
import sys

if sys.version_info > (3, 7):
    class Nested1:
        assignment = 1
        def function_definition(self): ...

    def f1(self) -> str: ...

    class Nested2:
        def function_definition(self): ...
        assignment = 1
    def f2(self) -> str: ...

if sys.version_info > (3, 7):
    def nested1():
        assignment = 1
        def function_definition(self): ...

    def f1(self) -> str: ...
    def nested2():
        def function_definition(self): ...
        assignment = 1
    def f2(self) -> str: ...
```

In the stable formatting, we have a blank line sometimes, not depending on the previous statement on the same level, but on the last (potentially nested) statement in the previous body.

#2783/#3564 fixes this for classes in preview style:

```python
import sys

if sys.version_info > (3, 7):
    class Nested1:
        assignment = 1
        def function_definition(self): ...

    def f1(self) -> str: ...

    class Nested2:
        def function_definition(self): ...
        assignment = 1

    def f2(self) -> str: ...

if sys.version_info > (3, 7):
    def nested1():
        assignment = 1
        def function_definition(self): ...

    def f1(self) -> str: ...
    def nested2():
        def function_definition(self): ...
        assignment = 1
    def f2(self) -> str: ...
```

This PR additionally fixes this for function definitions:

```python
if sys.version_info > (3, 7):
    if sys.platform == "win32":
        assignment = 1
        def function_definition(self): ...

    def f1(self) -> str: ...
    if sys.platform != "win32":
        def function_definition(self): ...
        assignment = 1

    def f2(self) -> str: ...

if sys.version_info > (3, 8):
    if sys.platform == "win32":
        assignment = 1
        def function_definition(self): ...

    class F1: ...
    if sys.platform != "win32":
        def function_definition(self): ...
        assignment = 1

    class F2: ...
```

You can see the effect of this change on typeshed in https://github.com/konstin/typeshed/pull/1/files. As baseline, the preview mode changes without this PR are at https://github.com/konstin/typeshed/pull/2.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-09-08 18:51:27 -07:00
..
async_as_identifier.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
blackd_diff.diff Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
blackd_diff.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
debug_visitor.out Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
debug_visitor.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
decorators.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
docstring_no_string_normalization.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
docstring_preview_no_string_normalization.py Remove invalid syntax in docstrings -S --preview test (#3205) 2022-08-02 17:22:04 -04:00
expression_skip_magic_trailing_comma.diff Draft for Black 2023 stable style (#3418) 2023-01-31 15:39:56 -08:00
force_py36.py More concise formatting for dummy implementations (#3796) 2023-08-03 19:11:21 -07:00
force_pyi.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
invalid_header.py Add option to skip the first line of source code (#3299) 2022-10-06 15:17:32 -07:00
linelength6.py Fix two docstring crashes (#3451) 2023-01-16 12:26:03 -08:00
long_strings_flag_disabled.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
missing_final_newline.diff Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
missing_final_newline.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
nested_stub.pyi Blank line between nested and function def in stub files. (#3862) 2023-09-08 18:51:27 -07:00
pattern_matching_invalid.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
power_op_newline.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
python2_detection.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
string_quotes.py Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
stub.pyi Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00