mirror of
https://github.com/python/cpython.git
synced 2025-09-19 15:10:58 +00:00
gh-131884: Fix incorrect formatting in json.dumps() when using indent and skipkeys=True (GH-132200)
This commit is contained in:
parent
485b499610
commit
ec12559eba
4 changed files with 20 additions and 7 deletions
|
@ -348,7 +348,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
|
||||
|
@ -381,6 +380,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)
|
||||
|
@ -413,7 +414,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
|||
except BaseException as exc:
|
||||
exc.add_note(f'when serializing {type(dct).__name__} item {key!r}')
|
||||
raise
|
||||
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