Format named expressions (walrus operator) (#5642)

## Summary

Format named expressions (walrus operator) such a `value := f()`. 

Unlike tuples, named expression parentheses are not part of the range
even when mandatory, so mapping optional parentheses to always gives us
decent formatting without implementing all [PEP
572](https://peps.python.org/pep-0572/) rules on when we need
parentheses where other expressions wouldn't. We might want to revisit
this decision later and implement special cases, but for now this gives
us what we need.

## Test Plan

black fixtures, i added some fixtures and checked django and cpython for
stability.

Closes #5613
This commit is contained in:
konsti 2023-07-10 14:32:15 +02:00 committed by GitHub
parent 1e894f328c
commit bd8f65814c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 152 additions and 318 deletions

View file

@ -0,0 +1,13 @@
y = 1
if (
# 1
x # 2
:= # 3
y # 4
):
pass
y0 = (y1 := f(x))
f(x:=y, z=True)