[issue29463] Add `docstring` attribute to AST nodes

2017-02-11 Thread Jeff Allen
Jeff Allen added the comment: Just terminology ... strictly speaking what you've done here is "add a *field* to the nodes Module, FunctionDef and ClassDef", rather than add an *attribute* -- that is, when one is consistent with the terms used in the ast module (https://docs.python.org/3/librar

[issue29463] Add `docstring` attribute to AST nodes

2017-02-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Therefore we loss the possibility to set a breakpoint on the docstring? It doesn't look a great lost. -- ___ Python tracker ___ _

[issue29463] Add `docstring` attribute to AST nodes

2017-02-08 Thread INADA Naoki
INADA Naoki added the comment: Now I doubt about this patch is really good. docstring of Module and Class generates two bytecode. So it's a real, executed statement. LOAD_CONST 0 ("docstring") STORE_NAME 0 ("__doc__") -- ___ Python tracker

[issue29463] Add `docstring` attribute to AST nodes

2017-02-08 Thread INADA Naoki
INADA Naoki added the comment: So what's new entry may be: +* ``Module``, ``FunctionDef``, ``AsyncFunctionDef``, and + ``ClassDef`` AST nodes now have a new ``docstring`` attribute. + The first statement in their body is not considered as a docstring anymore. + This affects ``co_firstlineno``

[issue29463] Add `docstring` attribute to AST nodes

2017-02-08 Thread INADA Naoki
INADA Naoki added the comment: This patch affects firstlineno and lnotab of module and class, but not functions. module: - at 0x7f053a8f8b70, file "Lib/importlib/_bootstrap.py", line 8> + at 0x7fdefbf10340, file "Lib/importlib/_bootstrap.py", line 25> filename Lib/importlib/_bootstrap.py -fi

[issue29463] Add `docstring` attribute to AST nodes

2017-02-08 Thread STINNER Victor
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 leve

[issue29463] Add `docstring` attribute to AST nodes

2017-02-08 Thread STINNER Victor
STINNER Victor added the comment: 2017-02-08 10:08 GMT+01:00 INADA Naoki : > 6 def func2(): > 7 """func docstring""" > 8 1+1 1+1 is replaced with 2 and lone integer literals are removed by the peephole optimizer. See also the issue #26204. -- _

[issue29463] Add `docstring` attribute to AST nodes

2017-02-08 Thread INADA Naoki
INADA Naoki added the comment: Oh, I misunderstood something. patched Python 3.7 and system's Python 3.5 shows same output for code below. I'll check what is actually changed. inada-n@x250 ~/w/p/ast-docstring> cat -n x.py 1 """module docstring""" 2 3 def func(): 4 "

[issue29463] Add `docstring` attribute to AST nodes

2017-02-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Support adding tests. Tests should cover all cases: module, class, function, coroutine and check also the first line number. What is the value of co_firstlineno if the function doesn't have any statements? def f(): '''docstring''' -- __

[issue29463] Add `docstring` attribute to AST nodes

2017-02-08 Thread STINNER Victor
STINNER Victor added the comment: def func(): "doc" + "string" Currently (Python 2.7-3.6), func.__doc__ is None. I suggest to add an unit test for this corner case, even if the result is going to change in a near future. We need to "specify" the expected behaviour, and make sure that we get th

[issue29463] Add `docstring` attribute to AST nodes

2017-02-07 Thread INADA Naoki
Changes by INADA Naoki : -- title: Change docstring to attribute from first statement. -> Add `docstring` attribute to AST nodes ___ Python tracker ___ _