Avoid removing whitespace for walrus operators within subscripts#3823
Avoid removing whitespace for walrus operators within subscripts#3823JelleZijlstra merged 7 commits intopsf:mainfrom charliermarsh:charlie/walrus
Conversation
|
A related question -- Black's stable style uses: a[:(x := 13)]Perhaps this should instead be: a[: (x := 13)](But I don't feel at all strongly here -- more asking if the stable style is intentional.) |
I think the latter would be more consistent, since we add spaces to e.g. |
JelleZijlstra
left a comment
There was a problem hiding this comment.
This looks good, thanks! However, the change should be made only in the preview style: we'll promote it to stable in January.
hauntsaninja
left a comment
There was a problem hiding this comment.
Thanks, this looks good! I made some minor changes to preview handling, tests and reformatted the source
|
Thanks! |
|
Tests are failing on 3.8/3.9 because of a change noted in https://docs.python.org/3.10/whatsnew/3.10.html#other-language-changes: "Assignment expressions can now be used unparenthesized within set literals and set comprehensions, as well as in sequence indexes (but not slices)." We should split out the offending tests into a separate test file that gets run only on 3.10+. |
Description
At present, Black removes spaces around walrus operators within subscripts. For example, this is stable style:
While rare in practice, it appears that this behavior is unintentional, and falls out from Black's removal of spaces around colons in slices (e.g.,
x[y:z]).This PR removes that behavior, instead requiring spaces around walrus operators in such cases.
Closes #3820.
Checklist - did you ...
CHANGES.mdif necessary?