Skip to content

Commit 4326fe8

Browse files
committed
Address review
1 parent 41b5baa commit 4326fe8

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

Doc/library/ast.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2439,8 +2439,8 @@ and classes for traversing abstract syntax trees:
24392439
indents that many spaces per level. If *indent* is a string (such as ``"\t"``),
24402440
that string is used to indent each level.
24412441

2442-
If *show_empty* is ``False``, then empty lists, fields that are ``None``,
2443-
and empty strings will be omitted from the output for better readability.
2442+
If *show_empty* is ``False``, then empty lists and fields that are ``None``
2443+
will be omitted from the output for better readability.
24442444

24452445
.. versionchanged:: 3.9
24462446
Added the *indent* option.

Lib/ast.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ def dump(
129129
include_attributes can be set to true. If indent is a non-negative
130130
integer or string, then the tree will be pretty-printed with that indent
131131
level. None (the default) selects the single line representation.
132-
If show_empty is False, then empty lists, fields that are None,
133-
and empty strings will be ommitted from the output for better readability.
132+
If show_empty is False, then empty lists and fields that are None
133+
will be ommitted from the output for better readability.
134134
"""
135135
def _format(node, level=0):
136136
if indent is not None:
@@ -156,7 +156,7 @@ def _format(node, level=0):
156156
continue
157157
if (
158158
not show_empty
159-
and value in empty_values
159+
and (value is None or value == [])
160160
and not isinstance(node, Constant)
161161
):
162162
# Special case: `Constant(value=None)`
@@ -191,7 +191,6 @@ def _format(node, level=0):
191191
raise TypeError('expected AST, got %r' % node.__class__.__name__)
192192
if indent is not None and not isinstance(indent, str):
193193
indent = ' ' * indent
194-
empty_values = (None, [])
195194
return _format(node)[0]
196195

197196

0 commit comments

Comments
 (0)