black/tests/data
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
..
fast Fix crash with walrus + await + with (#3473) 2023-01-17 22:25:05 -08:00
gitignore_used_on_multiple_sources Apply .gitignore correctly in every source entry (#3336) 2022-11-04 22:09:59 -07:00
ignore_subfolders_gitignore_tests Compare each .gitignore found with an appropiate relative path (#3338) 2022-11-08 07:50:04 -08:00
include_exclude_tests Do not use gitignore if explicitly passing excludes (#2170) 2021-05-07 14:54:21 +02:00
invalid_gitignore_tests Present a more user-friendly error if .gitignore is invalid (#2414) 2021-08-20 19:54:53 -04:00
invalid_nested_gitignore_tests Present a more user-friendly error if .gitignore is invalid (#2414) 2021-08-20 19:54:53 -04:00
jupyter Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
miscellaneous Blank line between nested and function def in stub files. (#3862) 2023-09-08 18:51:27 -07:00
nested_gitignore_tests Fix: black only respects the root gitignore. (#2225) 2021-05-16 13:51:27 -04:00
preview Avoid removing whitespace for walrus operators within subscripts (#3823) 2023-09-08 07:37:13 -07:00
preview_context_managers Consistently format async statements similar to their non-async version. (#3609) 2023-03-16 13:31:27 -07:00
preview_py_310 Avoid removing whitespace for walrus operators within subscripts (#3823) 2023-09-08 07:37:13 -07:00
project_metadata Infer target version based on project metadata (#3219) 2023-01-31 18:00:17 -08:00
py_36 Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
py_37 Remove hard coded test cases (#3062) 2022-05-18 12:11:37 -07:00
py_38 Draft for Black 2023 stable style (#3418) 2023-01-31 15:39:56 -08:00
py_39 Draft for Black 2023 stable style (#3418) 2023-01-31 15:39:56 -08:00
py_310 Draft for Black 2023 stable style (#3418) 2023-01-31 15:39:56 -08:00
py_311 Draft for Black 2023 stable style (#3418) 2023-01-31 15:39:56 -08:00
py_312 Add support for PEP 695 syntax (#3703) 2023-06-01 18:37:08 -07:00
simple_cases Fix crash on type comment with trailing space (#3773) 2023-07-09 16:28:26 -07:00
type_comments Support files with type comment syntax errors (#3594) 2023-03-19 18:52:06 -04:00
conditional_expression.py Parenthesize conditional expressions (#2278) 2022-12-29 15:13:15 -08:00
empty_pyproject.toml Support pyproject.toml 2018-06-06 17:02:10 -07:00