Skip to content

Commit ae00fb1

Browse files
bpo-30877: Fix clearing a cache in the the JSON decoder. (GH-7048)
1 parent 55bfe69 commit ae00fb1

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Lib/json/scanner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ def scan_once(string, idx):
6868
finally:
6969
memo.clear()
7070

71-
return _scan_once
71+
return scan_once
7272

7373
make_scanner = c_make_scanner or py_make_scanner

Lib/test/test_json/test_decode.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def check_keys_reuse(self, source, loads):
5858
def test_keys_reuse(self):
5959
s = '[{"a_key": 1, "b_\xe9": 2}, {"a_key": 3, "b_\xe9": 4}]'
6060
self.check_keys_reuse(s, self.loads)
61-
self.check_keys_reuse(s, self.json.decoder.JSONDecoder().decode)
61+
decoder = self.json.decoder.JSONDecoder()
62+
self.check_keys_reuse(s, decoder.decode)
63+
self.assertFalse(decoder.memo)
6264

6365
def test_extra_data(self):
6466
s = '[1, 2, 3]5'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed a bug in the Python implementation of the JSON decoder that prevented
2+
the cache of parsed strings from clearing after finishing the decoding.
3+
Based on patch by c-fos.

0 commit comments

Comments
 (0)