Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:
I am not sure that it should be fixed. We already cut corners in similar cases and did this for years, and it always was okay. In the following example bool(a) is only called once: if a and b: f() 1 0 LOAD_NAME 0 (a) 2 POP_JUMP_IF_FALSE 14 4 LOAD_NAME 1 (b) 6 POP_JUMP_IF_FALSE 14 2 8 LOAD_NAME 2 (f) 10 CALL_FUNCTION 0 12 POP_TOP >> 14 LOAD_CONST 0 (None) 16 RETURN_VALUE It differs from the case of using temporary variable (optimization does not work here): t = a and b if t: f() 1 0 LOAD_NAME 0 (a) 2 JUMP_IF_FALSE_OR_POP 6 4 LOAD_NAME 1 (b) >> 6 STORE_NAME 2 (t) 2 8 LOAD_NAME 2 (t) 10 POP_JUMP_IF_FALSE 18 3 12 LOAD_NAME 3 (f) 14 CALL_FUNCTION 0 16 POP_TOP >> 18 LOAD_CONST 0 (None) 20 RETURN_VALUE (BTW, Python 3.10 produces less optimal code for that examples) ---------- nosy: +serhiy.storchaka _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42899> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com