[issue45456] operator 'pass' in 'if-else' linear expression

Steven D'Aprano report at bugs.python.org
Wed Oct 13 00:21:52 EDT 2021


Steven D'Aprano <steve+python at pearwood.info> added the comment:

This is not a bug, "pass" is not an operator, it is not an expression, it is a statement and is only allowed in places where statements are allowed.

The if expression requires all three operands to be expressions.

Even if "pass" was permitted, what would it do? What would be the value of x after this assignment?

    x = 1 if False else pass

If you need x to be undefined, use an if statement:


    if False:
        # this block is not run
        x = 1

    # x is undefined here

----------
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45456>
_______________________________________


More information about the Python-bugs-list mailing list