With Python 3.8 Assignment Expressions have been introduced, allowing to assign values in conditionals and lambdas as such:
if x := True:
print(x)
However it appears this does not extends to attribute assignment, as trying to do something like this
from typing import NamedTuple
class Test(NamedTuple):
field : bool
test = Test(field=False)
if test.field := True:
print(test.field)
Will result in the following error:
SyntaxError: cannot use named assignment with attribute
Is it really only possible to update attribute in assignment statements (as opposed to assignment expressions) and if yes why this limitation?