[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:
Serhiy Storchaka 2025-06-05 17:38:11 +03:00 committed by GitHub
parent 5a69d4fe00
commit e2a9a3fa98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 7 deletions

View file

@ -22,6 +22,14 @@ def test_dump_skipkeys(self):
self.assertIn('valid_key', o)
self.assertNotIn(b'invalid_key', o)
def test_dump_skipkeys_indent_empty(self):
v = {b'invalid_key': False}
self.assertEqual(self.json.dumps(v, skipkeys=True, indent=4), '{}')
def test_skipkeys_indent(self):
v = {b'invalid_key': False, 'valid_key': True}
self.assertEqual(self.json.dumps(v, skipkeys=True, indent=4), '{\n "valid_key": true\n}')
def test_encode_truefalse(self):
self.assertEqual(self.dumps(
{True: False, False: True}, sort_keys=True),