Skip to content

Empty AST nodes are confusingly represented with (...) (recursion depth stopper) #156021

Description

@johnslavik

Bug report

Bug description:

import ast
print(repr(ast.parse("x")))

Current vs expected:

-Module(body=[Expr(value=Name(id='x', ctx=Load(...)))], type_ignores=[])
+Module(body=[Expr(value=Name(id='x', ctx=Load()))], type_ignores=[])

If a node is empty, let's avoid adding ... that could suggest that there's something redacted within the node.

Thanks @asottile for reporting internally. I didn't find a duplicate.

CPython versions tested on:

CPython main branch, 3.15, 3.14

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions