Pablo Galindo Salgado <pablog...@gmail.com> added the comment:
Serhiy, this is the code that was incorrectly optimized: 3 0 LOAD_GLOBAL 0 (g) 2 LOAD_ATTR 1 (__code__) 4 POP_JUMP_IF_FALSE 8 6 JUMP_FORWARD 4 (to 12) >> 8 LOAD_CONST 0 (None) 10 POP_JUMP_IF_FALSE 20 4 >> 12 LOAD_GLOBAL 2 (print) 14 LOAD_CONST 2 ('Called!') 16 CALL_FUNCTION 1 18 POP_TOP >> 20 LOAD_CONST 0 (None) 22 RETURN_VALUE def g(): if True if g.__code__ else None: print("Called!") g() The problem is that [LOAD_CONST 0 (None)] made the peephole to delete the block because it does not detect that previous conditions in the same conditional could be True. The general case was made by looking back for POP_JUMP_IF_{FALSE,TRUE} but with this construct JUMP_FORWARD appears. I think handling this condition in the peephole optimizer can be very dangerous error prone to get right because all the information is lost, but doing it at the ast level makes us lose syntax errors in optimized blocks, which is also wrong. Any ideas? It happens here in Cython: https://github.com/cython/cython/blob/master/Cython/Compiler/Nodes.py#L5131 That's why the errors manifest as pickling errors ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37289> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com