mirror of
https://github.com/python/cpython.git
synced 2025-09-17 22:20:23 +00:00
gh-134718: Fix ast.dump() for empty non-default values (GH-134926)
This commit is contained in:
parent
ce6a6371a2
commit
cc344e8dd0
3 changed files with 36 additions and 12 deletions
22
Lib/ast.py
22
Lib/ast.py
|
@ -147,18 +147,16 @@ 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))
|
||||
):
|
||||
args_buffer.append(repr(value))
|
||||
continue
|
||||
elif not keywords:
|
||||
args.extend(args_buffer)
|
||||
args_buffer = []
|
||||
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
|
||||
if not keywords:
|
||||
args.extend(args_buffer)
|
||||
args_buffer = []
|
||||
value, simple = _format(value, level)
|
||||
allsimple = allsimple and simple
|
||||
if keywords:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue