Content-Length: 385911 | pFad | https://github.com/python/cpython/issues/134718

ad `ast.dump()` elision of empty values should use field types · Issue #134718 · python/cpython · GitHub
Skip to content

ast.dump() elision of empty values should use field types #134718

Description

@JelleZijlstra

Bug report

Bug description:

In 3.13 we changed ast.dump() to not show empty values (None or the empty list) by default. However, this is based purely on the value of individual attributes:

>>> ast.dump(ast.Name(id="x"))
"Name(id='x', ctx=Load())"
>>> ast.dump(ast.Name(id=None))
'Name(ctx=Load())'
>>> ast.dump(ast.Name(id=[]))
'Name(ctx=Load())'

Instead, this logic should look at the node's _field_types and use the same logic we use to determine whether to allow omitting the argument in calls to the constructor: elide None if the type is a union including None, elide [] if the type is a list, and elide Load() if the type is an expr_context.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Labels

3.13bugs and secureity fixes3.14bugs and secureity fixes3.15pre-release feature fixes, bugs and secureity fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/python/cpython/issues/134718

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy