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: Two if in a row in generators
Type: behavior Stage: resolved
Components: Parser Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, lys.nikolaou, pablogsal, serhiy.storchaka, stsouko
Priority: normal Keywords:

Created on 2022-02-07 09:44 by stsouko, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg412726 - (view) Author: Ramil Nugmanov (stsouko) Date: 2022-02-07 09:44
treat without error two if in generators.

>>>[x for x in [1, 2, 3] if 1 if 1]
[1, 2, 3]

>>>[x for x in [1, 2, 3] if 0 if 1]
[]

expected syntax error
msg412727 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-02-07 09:47
It is valid syntax.
msg412731 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2022-02-07 11:13
As Serhiy mentioned, this is a valid syntax.
msg412736 - (view) Author: Ramil Nugmanov (stsouko) Date: 2022-02-07 12:00
Yes,

[x for x in [1, 2, 3] if 1 if 1]

can be replaced with:

for x in [1, 2, 3]:
    if 1:
        if 1:
            yield x

However this syntax is strange and leads to errors like:

[x for x in [1, 2, 3] if x is not None] >> [x for x in [1, 2, 3] if x if not None]
msg412739 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-02-07 13:02
Please, stop reopening the issue.

The syntax is valid python syntax and we will not be able to make it invalid
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90832
2022-02-07 13:02:39pablogsalsetstatus: open -> closed
resolution: not a bug
messages: + msg412739
2022-02-07 12:00:04stsoukosetstatus: closed -> open
resolution: not a bug -> (no value)
messages: + msg412736
2022-02-07 11:13:26BTaskayasetstatus: open -> closed

nosy: + BTaskaya
messages: + msg412731

resolution: not a bug
stage: resolved
2022-02-07 09:47:20serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg412727
2022-02-07 09:44:17stsoukocreate