Zac-HD / shed

`shed` canonicalises Python code. Shed your legacy, stop bikeshedding, and move on. Black++
https://pypi.org/project/shed/
GNU Affero General Public License v3.0
342 stars 23 forks source link

add codemod for splitting up 'assert a and b' #51

Closed jakkdl closed 2 years ago

jakkdl commented 2 years ago

Fix first task in #22

First PR to this repo, so I assume there's some doc I should update. And very possible my implementation is bad in one way or another.

I wanted to leave the comment on the first assert, or put it on a separate line before the first assert (lmk which one you prefer). Will figure out how to do that unless you're fine with it staying on the line of the last assert.

Zac-HD commented 2 years ago

The only doc to update here is the changelog, since the readme is deliberately pretty vague about details in order to make releases easier! I'm also happy to leave comments attached to the last line.

I'll likely merge this as-is after some manual testing later today 🎉

Zac-HD commented 2 years ago

🤦‍♂️ immediately after merging: "I wonder what happens if you had assert a and b, 'some meaningful message'". Two more test-cases for a quick follow-up PR:

assert (
    a # comment on a
    and b  # comment on b
)
assert a and b, "avoid splitting if there's a message"

I imagine getting the comments associated with the right clauses in the first could be kinda annoying, sorry, but it's better UX!

jakkdl commented 2 years ago

haha, I thought it was a bit scary when you merged it immediately x) I expected something to be broken, so no worries - will figure it out!

jakkdl commented 2 years ago

This is becoming a thing, but I'm onto handling

assert ( # before
        a # a_comment
        # between a&and
        and #and_comment
        # between and&b
        b # b_comment
        # after
        ) # paren_comment

which I think should cover everything possible. Thought about "just" handling simpler cases but turns out they're about as messy, heh.