[issue29463] Add `docstring` attribute to AST nodes

STINNER Victor report at bugs.python.org
Wed Feb 8 04:35:53 EST 2017


STINNER Victor added the comment:

Oops, I spoke too fast :-) "1+1" is not removed.

"1+1" is replaced with "2" by the peephole optimizer, whereas the compiler ignoring constants comes before the peephole optimizer.

One more time, it would be better to implement constant folding at the AST level ;-)

$ python3
Python 3.5.2 (default, Sep 14 2016, 11:28:32) 
>>> def func():
...  "docstring"
...  1+1
... 
>>> import dis
>>> dis.dis(func)
  3           0 LOAD_CONST               3 (2)
              3 POP_TOP
              4 LOAD_CONST               2 (None)
              7 RETURN_VALUE

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29463>
_______________________________________


More information about the Python-bugs-list mailing list