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.

classification
Title: operator 'pass' in 'if-else' linear expression
Type: Stage: resolved
Components: Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: evgnor86, rhettinger, steven.daprano, wyz23x2
Priority: normal Keywords:

Created on 2021-10-13 03:58 by evgnor86, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (11)
msg403793 - (view) Author: Evgeniy Ivanov (evgnor86) Date: 2021-10-13 03:58
Why operator 'pass' not implement to 'if-else' linear expression?
Construction '<func/operation> if <expression> else pass' throws SyntaxError in Python 3.9
msg403795 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-10-13 04:21
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
msg403797 - (view) Author: Evgeniy Ivanov (evgnor86) Date: 2021-10-13 05:20
ok, but what you say for this?

x += x*2 if math.pow(x) > 386 else pass

and 

if math.pow(x) > 386:
 x += x*2

1 line vs 2 line

now i'm use this

x += x*2 if math.pow(x) > 386 else ''
msg403798 - (view) Author: Evgeniy Ivanov (evgnor86) Date: 2021-10-13 05:22
it is more readable
msg403799 - (view) Author: Evgeniy Ivanov (evgnor86) Date: 2021-10-13 05:25
or another example:

def my_func(x):
 something_do....


my_func(x) if x > 100 else <no call this function>
msg403800 - (view) Author: Evgeniy Ivanov (evgnor86) Date: 2021-10-13 05:29
this wrong example

now i'm use this
x += x*2 if math.pow(x) > 386 else ''

wanted to say that doing this now

my_func(x) if x > 100 else ''
msg403802 - (view) Author: Evgeniy Ivanov (evgnor86) Date: 2021-10-13 05:40
formaly it's not bug, this is future request ok?
msg403804 - (view) Author: wyz23x2 (wyz23x2) * Date: 2021-10-13 05:47
Well,
x = 1 if False else pass
and
if False: x = 1

1 line vs 1 line :) It's just not needed.
msg403805 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-10-13 05:58
If you want pass to become an expression, what should these do?

    x = pass

    print(pass)

    mydict[pass] = 1

    type(pass)

There is nothing special about the ternary if operator. It is just an 
operator like plus, minus and more. The only difference is that plus 
takes two arguments, and if...else takes three:

    expression + expression

    expression if expression else expression

If pass becomes legal in the if...else ternary operatory, it must be an 
expression, so it must have a value. What is that value?
msg403883 - (view) Author: Evgeniy Ivanov (evgnor86) Date: 2021-10-14 02:41
What about this?

if x > 2: my_func(x)

ok this code at 1 line, this code work, but...

PEP 8: E701 multiple statements on one line (colon)


Well f//k it with a pass
Why not add an empty action operator? What is the problem? Such an instruction has existed since the days of assembler - nop
msg403885 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-10-14 04:48
Evgeniy, please leave this closed and take the proposal to the python-ideas mailing list.   There is no further progress that can be made in this tracker issue.  We can’t discern any part of your proposal that would make sense for improving the language.
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89619
2021-10-14 04:48:30rhettingersetstatus: open -> closed


messages: + msg403885
nosy: + rhettinger
2021-10-14 02:41:45evgnor86setstatus: closed -> open

messages: + msg403883
2021-10-13 08:27:36serhiy.storchakasetstatus: open -> closed
resolution: not a bug
2021-10-13 05:58:40steven.dapranosetmessages: + msg403805
title: 'pass' in 'if-else' linear expression -> operator 'pass' in 'if-else' linear expression
2021-10-13 05:47:38wyz23x2setnosy: + wyz23x2
messages: + msg403804
2021-10-13 05:41:47evgnor86settitle: operator 'pass' in 'if-else' linear expression -> 'pass' in 'if-else' linear expression
2021-10-13 05:40:05evgnor86setmessages: + msg403802
2021-10-13 05:29:17evgnor86setmessages: + msg403800
2021-10-13 05:25:14evgnor86setmessages: + msg403799
2021-10-13 05:22:21evgnor86setmessages: + msg403798
2021-10-13 05:20:51evgnor86setmessages: + msg403797
2021-10-13 05:17:18evgnor86setstatus: closed -> open
type: compile error ->
resolution: not a bug -> (no value)
2021-10-13 04:21:52steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg403795

resolution: not a bug
stage: resolved
2021-10-13 03:58:17evgnor86create