Author lukasz.langa
Recipients Mark.Shannon, benjamin.peterson, georg.brandl, inada.naoki, lukasz.langa, ned.deily, rhettinger, serhiy.storchaka, vstinner
Date 2018-03-12.20:43:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1520887438.38.0.467229070634.issue32911@psf.upfronthosting.co.za>
In-reply-to
Content
Python's AST already doesn't include a lot of syntax that has no runtime effect:
- comments;
- whitespace and punctuation.

The situation is now made "worse" with constant folding.  You won't have full line information on the full expression, you don't even fully *see* expressions as syntactically provided by user code.  The docstring is just a special case of that.

As a counter example, it still includes function-level type annotations which are not evaluated. Clearly we don't have an explicit rule about this.

If you asked *me*, I would say Python provides a "lossy" AST and this is the one it itself uses.  It also provides a "lossless" AST and this one is in lib2to3.  It's unfortunate that the latter is not documented and kind of neglected.  This is something I want to address soonish.

Summing up, I'm in favor of option 3.  The AST preserves the docstring, it simply doesn't have information on where exactly it lives.  In exchange, the tree makes it easier to *find* the docstring and easier to find the first instruction (as Serhiy points out, the first statement is now always code to be executed).

Quoting literally the second sentence of the `ast` documentation:
> The abstract syntax itself might change with each Python release.

I am not against Option 2 since it's already implemented but I feel it's a pretty big change, pretty late in the release process for 3.7.  The amount of work required *just* to preserve the line number of the docstring (which can be reasonably guessed anyway) seems silly to me.
History
Date User Action Args
2018-03-12 20:43:58lukasz.langasetrecipients: + lukasz.langa, georg.brandl, rhettinger, vstinner, benjamin.peterson, ned.deily, inada.naoki, Mark.Shannon, serhiy.storchaka
2018-03-12 20:43:58lukasz.langasetmessageid: <1520887438.38.0.467229070634.issue32911@psf.upfronthosting.co.za>
2018-03-12 20:43:58lukasz.langalinkissue32911 messages
2018-03-12 20:43:58lukasz.langacreate