Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't strip parens in assert / return with assign expr #2143

Merged

Conversation

ichard26
Copy link
Collaborator

@ichard26 ichard26 commented Apr 26, 2021

Black would previously strip the parenthesis away from statements like this these ones:

assert (spam := 12 + 1)
return (cheese := 1 - 12)

Which happens to be invalid code. Now before making the parenthesis invisible, Black
checks if the assignment expression's parent is an assert stamtment, aborting if True.

Raise, yield, and await are already handled fine.

I added a bunch of test cases from the PEP defining asssignment expressions (PEP 572).

@ichard26 ichard26 force-pushed the fix-assert-stmt-with-assignment-expr branch from 1a10814 to 4570dd5 Compare April 26, 2021 15:02
@ichard26 ichard26 marked this pull request as draft April 26, 2021 15:09
Black would previously strip the parenthesis away from statements like this these ones:

    assert (spam := 12 + 1)
    return (cheese := 1 - 12)

Which happens to be invalid code. Now before making the parenthesis invisible, Black
checks if the assignment expression's parent is an assert stamtment, aborting if True.

Raise, yield, and await are already handled fine.

I added a bunch of test cases from the PEP defining asssignment expressions (PEP 572).
@ichard26 ichard26 force-pushed the fix-assert-stmt-with-assignment-expr branch from 4570dd5 to 0cf1193 Compare April 26, 2021 15:21
@ichard26 ichard26 changed the title Don't remove parens in asserts with assigment expr Don't strip parens in assert / return with assign expr Apr 26, 2021
@ichard26 ichard26 marked this pull request as ready for review April 26, 2021 15:22
@JelleZijlstra JelleZijlstra merged commit db30456 into psf:master Apr 26, 2021
@ichard26 ichard26 deleted the fix-assert-stmt-with-assignment-expr branch April 26, 2021 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants