]> git.madduck.net Git - etc/vim.git/commit

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Treat functions/classes in blocks as if they're nested (GH-2472)
authorRichard Si <63936253+ichard26@users.noreply.github.com>
Wed, 1 Dec 2021 23:05:59 +0000 (18:05 -0500)
committerGitHub <noreply@github.com>
Wed, 1 Dec 2021 23:05:59 +0000 (18:05 -0500)
commitb0c2bcc9537d238c8a580294ecbc41de465d7f55
tree1595662b963b21ddb0013c6c08af467436ca5835
parent84851914488b2f3f6388a0760ee04306e4c2fc18
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>
CHANGES.md
src/black/lines.py
src/black_primer/primer.json
tests/data/function2.py