mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
[3.13] gh-134718: Fix ast.dump() for empty non-default values (GH-134926) (GH-134936)
(cherry picked from commit cc344e8dd0
)
This commit is contained in:
parent
7fdc829bc2
commit
681856c194
3 changed files with 24 additions and 12 deletions
14
Lib/ast.py
14
Lib/ast.py
|
@ -151,16 +151,14 @@ def dump(
|
|||
if value is None and getattr(cls, name, ...) is None:
|
||||
keywords = True
|
||||
continue
|
||||
if (
|
||||
not show_empty
|
||||
and (value is None or value == [])
|
||||
# Special cases:
|
||||
# `Constant(value=None)` and `MatchSingleton(value=None)`
|
||||
and not isinstance(node, (Constant, MatchSingleton))
|
||||
):
|
||||
if not show_empty:
|
||||
if value == []:
|
||||
field_type = cls._field_types.get(name, object)
|
||||
if getattr(field_type, '__origin__', ...) is list:
|
||||
if not keywords:
|
||||
args_buffer.append(repr(value))
|
||||
continue
|
||||
elif not keywords:
|
||||
if not keywords:
|
||||
args.extend(args_buffer)
|
||||
args_buffer = []
|
||||
value, simple = _format(value, level)
|
||||
|
|
|
@ -1346,12 +1346,24 @@ Module(
|
|||
full="MatchSingleton(value=None)",
|
||||
)
|
||||
|
||||
check_node(
|
||||
ast.MatchSingleton(value=[]),
|
||||
empty="MatchSingleton(value=[])",
|
||||
full="MatchSingleton(value=[])",
|
||||
)
|
||||
|
||||
check_node(
|
||||
ast.Constant(value=None),
|
||||
empty="Constant(value=None)",
|
||||
full="Constant(value=None)",
|
||||
)
|
||||
|
||||
check_node(
|
||||
ast.Constant(value=[]),
|
||||
empty="Constant(value=[])",
|
||||
full="Constant(value=[])",
|
||||
)
|
||||
|
||||
check_node(
|
||||
ast.Constant(value=""),
|
||||
empty="Constant(value='')",
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
:func:`ast.dump` now only omits ``None`` and ``[]`` values if they are
|
||||
default values.
|
Loading…
Add table
Add a link
Reference in a new issue