[issue32911] Doc strings omitted from AST

2018-02-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Note, that getting the location of the dostring already was a pain since in case of multiline string literals CPython saves the location of the last line, and PyPy saves the location of the first line. Getting the location of

[issue32911] Doc strings omitted from AST

2018-02-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I prefer 2 or 3. There are benefits from representing a docstring as a separate attribute. This simplifies the code for walking the AST tree (no longer special cases for skipping docstring in modules, classes and functions) and

[issue32911] Doc strings omitted from AST

2018-02-23 Thread Mark Shannon
Mark Shannon added the comment: Serhiy, thanks for reopening this issue. It seems to be that there are three reasonable choices: 1. Revert to 3.6 behaviour, with the addition of `docstring` attribute. 2. Change the docstring attribute to an AST node, possibly by modifying the

[issue32911] Doc strings omitted from AST

2018-02-22 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It may be worth to include docstrings explicitly in the grammar. -- resolution: fixed -> stage: resolved -> status: closed -> open ___ Python tracker

[issue32911] Doc strings omitted from AST

2018-02-22 Thread Ned Deily
Ned Deily added the comment: It seems we have a difference of opinion here. Serhiy closed this issue so, Mark, if you feel strongly enough to pursue it, you should reopen it and solicit other opinions. The clock has just about run out to change the now current behavior for

[issue32911] Doc strings omitted from AST

2018-02-22 Thread Mark Shannon
Mark Shannon added the comment: Stating that "this is a feature not a bug" does not make it so. This breaks existing code and reduces the capabilities of the `ast` module. For example, how does one get the location of the docstring now? >From a syntactic point of view. def

[issue32911] Doc strings omitted from AST

2018-02-22 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This isn't a bug, but a feature. You no longer need to check and skip the first statement if it is a literal string. The body attribute now always represents a sequence of statements, and the docstring attribute represents a

[issue32911] Doc strings omitted from AST

2018-02-22 Thread INADA Naoki
Change by INADA Naoki : -- components: +Interpreter Core -Library (Lib) ___ Python tracker ___

[issue32911] Doc strings omitted from AST

2018-02-22 Thread INADA Naoki
INADA Naoki added the comment: We implemented AST-level constant folding (#29469) based on the AST change (#29463). I feel it's possible to revert AST change without reverting AST constant folding: * Docstring is exposed from AST before calling AST optimizer. * AST

[issue32911] Doc strings omitted from AST

2018-02-22 Thread Mark Shannon
Mark Shannon added the comment: That issue has to do with bytecode generation, not the AST. The AST should be an accurate representation of the Python source code. Making a better representation of the source would be fine, but this makes it worse. Doc-strings may be

[issue32911] Doc strings omitted from AST

2018-02-22 Thread INADA Naoki
INADA Naoki added the comment: ref: https://bugs.python.org/issue29463 -- ___ Python tracker ___

[issue32911] Doc strings omitted from AST

2018-02-22 Thread Mark Shannon
Mark Shannon added the comment: This is an unnecessary and breaking change. Changes like this should not be made unless necessary to fix a bug. -- ___ Python tracker

[issue32911] Doc strings omitted from AST

2018-02-22 Thread INADA Naoki
INADA Naoki added the comment: AST is changed slightly from Python 3.7. ast.get_docstring() works for both of 3.6 and 3.7. $ ./python Python 3.8.0a0 (heads/master-dirty:451d1edaf4, Feb 22 2018, 21:11:54) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or

[issue32911] Doc strings omitted from AST

2018-02-22 Thread Mark Shannon
New submission from Mark Shannon : Python 3.7.0b1+ (heads/3.7:dfa1144, Feb 22 2018, 12:10:59) >>> m = ast.parse("def foo():\n 'help'") >>> m.body[0].body [] Correct behaviour (3.6 or earlier) >>> m = ast.parse("def foo():\n 'help'") >>> m.body[0].body [<_ast.Expr object