This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author FuturisticGoo
Recipients FuturisticGoo
Date 2021-01-28.11:58:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1611835115.72.0.951775533132.issue43055@roundup.psfhosted.org>
In-reply-to
Content
Using the walrus operator (:=) alongside 'and'/'or' shows inconsistent behaviour which changes with the order of given conditions. 

For example:
if(False and (x := 0)<1):
    print("Yes")
else:
    print(x)

Gives the error that 'NameError: name 'x' is not defined'
Whereas if the walrus operator is used first, like:
if((x := 0)>1 and False):
    print("Yes")
else:
    print(x)

Prints the value 0 without any error. This behaviour is the same when using 'or'. For example:

if(True or (y:=0)<1):
    print(y)
else:
    print("No")

Gives the same error but this:
if((y:=0)<1 or True):
    print(y)
else:
    print("No")

Prints the value 0.
I am guessing that this is because 'and' doesn't check the second operand if the first operand is False, also 'if' doesn't check the second operand if the first operand is True. I don't know if this is an intended behaviour.

Thanks
History
Date User Action Args
2021-01-28 11:58:35FuturisticGoosetrecipients: + FuturisticGoo
2021-01-28 11:58:35FuturisticGoosetmessageid: <1611835115.72.0.951775533132.issue43055@roundup.psfhosted.org>
2021-01-28 11:58:35FuturisticGoolinkissue43055 messages
2021-01-28 11:58:35FuturisticGoocreate