[issue26204] compiler: don't emit LOAD_CONST instructions for constant statements?
STINNER Victor
report at bugs.python.org
Tue Jan 26 17:05:19 EST 2016
STINNER Victor added the comment:
"""
Will the following code compile OK? What will it compile to?
if 1:
42
"""
compile OK: what do you mean? This code doesn't make any sense to me :-)
Currently text strings statements are ignored:
---
>>> def f():
... if 1:
... "abc"
...
>>> import dis
>>> dis.dis(f)
3 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
---
But byte strings emit a LOAD_CONST+POP_TOP:
---
>>> def g():
... if 1:
... b'bytes'
...
>>> dis.dis(g)
3 0 LOAD_CONST 1 (b'bytes')
3 POP_TOP
4 LOAD_CONST 0 (None)
7 RETURN_VALUE
---
With my patch, all constants statements will be ignored. Example with my patch:
---
>>> def h():
... if 1:
... b'bytes'
...
>>> import dis; dis.dis(h)
3 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
---
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26204>
_______________________________________
More information about the Python-bugs-list
mailing list