This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pekka.klarck
Recipients pekka.klarck
Date 2019-11-11.14:31:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1573482663.72.0.733055997415.issue38765@roundup.psfhosted.org>
In-reply-to
Content
We have implemented an ast for our own tool so that we extend Python's standard `ast.AST`. When using `ast.dump(node, include_attributes=True)`, we were surprised to notice that line numbers weren't dumped although the docs of `ast.dump()` said they should be and we had set both `lineno` and `end_lineno` attributes to our nodes.

Looking at the implementation of `ast.dump()` revealed that `include_attributes=True` alone wasn't enough, the node also needed to have `_attributes` attribute similarly as it needs to have `_fields` for `ast.dump()` to be able to dump also child nodes. The problem is that `_attributes` isn't documented at all. Related to that, `ast.dump()` using `_fields` isn't documented either, but at least `_fields` is mentioned in the docs otherwise. Relevant links to `ast.dump()` docs and to the source code below.

`ast.AST` documents the `_fields` attribute but doesn't mention similar `_attributes`:
https://docs.python.org/3/library/ast.html#ast.AST

`ast.dump()` documents the `include_attributes` argument but doesn't mention that `_attributes` is needed (or that `_fields` needs to be set correctly to get child notes dumped):
https://docs.python.org/3/library/ast.html#ast.dump

`ast.dump()` source code shows that the undocumented `_attributes` needs to be set in addition to using `include_attributes=True`:
https://github.com/python/cpython/blob/3.8/Lib/ast.py#L123
History
Date User Action Args
2019-11-11 14:31:03pekka.klarcksetrecipients: + pekka.klarck
2019-11-11 14:31:03pekka.klarcksetmessageid: <1573482663.72.0.733055997415.issue38765@roundup.psfhosted.org>
2019-11-11 14:31:03pekka.klarcklinkissue38765 messages
2019-11-11 14:31:03pekka.klarckcreate