mirror of
https://github.com/python/cpython.git
synced 2025-08-10 11:58:39 +00:00
[3.13] gh-131884: Fix incorrect formatting in json.dumps() when using indent and skipkeys=True (GH-132200) (GH-135061)
(cherry picked from commit ec12559eba
)
Co-authored-by: Roei Ben Artzi <155478676+roeibenartzi@users.noreply.github.com>
This commit is contained in:
parent
5a69d4fe00
commit
e2a9a3fa98
4 changed files with 22 additions and 7 deletions
|
@ -345,7 +345,6 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
|||
_current_indent_level += 1
|
||||
newline_indent = '\n' + _indent * _current_indent_level
|
||||
item_separator = _item_separator + newline_indent
|
||||
yield newline_indent
|
||||
else:
|
||||
newline_indent = None
|
||||
item_separator = _item_separator
|
||||
|
@ -378,6 +377,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
|||
f'not {key.__class__.__name__}')
|
||||
if first:
|
||||
first = False
|
||||
if newline_indent is not None:
|
||||
yield newline_indent
|
||||
else:
|
||||
yield item_separator
|
||||
yield _encoder(key)
|
||||
|
@ -404,7 +405,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
|||
else:
|
||||
chunks = _iterencode(value, _current_indent_level)
|
||||
yield from chunks
|
||||
if newline_indent is not None:
|
||||
if not first and newline_indent is not None:
|
||||
_current_indent_level -= 1
|
||||
yield '\n' + _indent * _current_indent_level
|
||||
yield '}'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue