Author Zoran Simic
Recipients Zoran Simic
Date 2019-11-20.23:12:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574291556.7.0.332589714744.issue38871@roundup.psfhosted.org>
In-reply-to
Content
This code snippet exposes a small edge case in lib2to3, where syntactically invalid code is generated:

data = [1, 2, 3, 4, 5]
x = filter(lambda x: True if x > 2 else False, data)
print(x)


lib2to3 transforms 2nd line above to:
x = [x for x in data if True if x > 2 else False]


which is invalid (would be OK with parentheses after 1st 'if')

Admittedly, the original code here is more complex that it should be ('True if foo else False' being equivalent to just 'foo'), but walked into this in "the real world" and wanted to report it.
History
Date User Action Args
2019-11-20 23:12:36Zoran Simicsetrecipients: + Zoran Simic
2019-11-20 23:12:36Zoran Simicsetmessageid: <1574291556.7.0.332589714744.issue38871@roundup.psfhosted.org>
2019-11-20 23:12:36Zoran Simiclinkissue38871 messages
2019-11-20 23:12:36Zoran Simiccreate