black/tests
Richard Si b0c2bcc953
Treat functions/classes in blocks as if they're nested (GH-2472)
* Treat functions/classes in blocks as if they're nested

One curveball is that we still want two preceding newlines before blocks
that are probably logically disconnected. In other words:

    if condition:

        def foo():
            return "hi"
                             # <- aside: this is the goal of this commit
    else:

        def foo():
            return "cya"
                             # <- the two newlines spacing here should stay
                             #    since this probably isn't related
    with open("db.json", encoding="utf-8") as f:
        data = f.read()

Unfortunately that means we have to special case specific clause types
instead of just being able to just for a colon leaf. The hack used here
is to check whether we're adding preceding newlines for a standalone or
dependent clause. "Standalone" being a clause that doesn't need another
clause to be valid (eg. if) and vice versa.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2021-12-01 18:05:59 -05:00
..
data Treat functions/classes in blocks as if they're nested (GH-2472) 2021-12-01 18:05:59 -05:00
__init__.py Remove deprecated use of 'setup.py test' (#1275) 2020-05-08 06:23:50 -07:00
conftest.py Use optional tests for "no_python2" to simplify local testing (#2203) 2021-05-07 15:03:13 +02:00
empty.toml Add --target-version option to allow users to choose targeted Python versions (#618) 2019-02-06 18:43:50 -08:00
optional.py add more flake8 lints (#2653) 2021-11-28 18:20:52 -08:00
test_black.py add more flake8 lints (#2653) 2021-11-28 18:20:52 -08:00
test_blackd.py re-implement simple CORS middleware for blackd (#2500) 2021-09-25 12:58:44 +01:00
test_format.py fix error message for match (#2649) 2021-11-30 18:39:39 -08:00
test_ipynb.py Return NothingChanged if non-Python cell magic is detected, to avoid tokenize error (#2630) 2021-11-29 15:07:35 -08:00
test_no_ipynb.py Jupyter notebook support (#2357) 2021-08-06 16:57:46 -04:00
test_primer.py Use STDIN project in test_projects to ensure it runs quickly (#2575) 2021-10-30 11:54:43 -07:00
test_trans.py Fix determination of f-string expression spans (#2654) 2021-12-01 09:52:24 -08:00
test.toml Switch toml TOML library for tomli (#2301) 2021-07-12 16:01:38 -04:00
util.py Print out line diff on test failure (#2552) 2021-10-27 07:37:20 -07:00