Issue 3275: Control flow not optimized (original) (raw)

Issue3275

Created on 2008-07-03 20:43 by quotemstr, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg69230 - (view) Author: Daniel Colascione (quotemstr) Date: 2008-07-03 20:43
Consider: import dis def foo(): if 0 and 1: return "hi" dis.dis(foo) What I get is 2 0 LOAD_CONST 1 (0) 3 JUMP_IF_FALSE 15 (to 21) 6 POP_TOP 7 LOAD_CONST 2 (1) 10 JUMP_IF_FALSE 8 (to 21) 13 POP_TOP 14 LOAD_CONST 3 ('hi') 17 RETURN_VALUE 18 JUMP_FORWARD 1 (to 22) >> 21 POP_TOP >> 22 LOAD_CONST 0 (None) 25 RETURN_VALUE What I'd expect to see is: 1 0 LOAD_CONST 0 (None) 3 RETURN_VALUE
msg69231 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-03 20:51
A patch for this was just recently rejected. See #1394.
msg69248 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-07-04 09:05
What real-life use case do you have for a condition that is a boolean operation on two constant values anyway? Things like while 1: ... are properly optimized since they serve a useful purpose.
History
Date User Action Args
2022-04-11 14:56:36 admin set github: 47525
2008-07-04 09:05:53 georg.brandl set nosy: + georg.brandlmessages: +
2008-07-03 20:51:29 benjamin.peterson set status: open -> closedresolution: rejectedmessages: + nosy: + benjamin.peterson
2008-07-03 20:43:13 quotemstr create