]> granicus.if.org Git - python/commitdiff
bpo-30877: Fix clearing a cache in the the JSON decoder. (GH-7048)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 22 May 2018 13:03:10 +0000 (06:03 -0700)
committerGitHub <noreply@github.com>
Tue, 22 May 2018 13:03:10 +0000 (06:03 -0700)
(cherry picked from commit ae00fb1d4f38ea1803b10d798564740adcdad63e)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/json/scanner.py
Lib/test/test_json/test_decode.py
Misc/NEWS.d/next/Library/2018-05-22-13-05-12.bpo-30877.JZEGjI.rst [new file with mode: 0644]

index c451ebab58425558fdcae432a8a75bd161d76738..7a61cfc2d24dceb3530988884f70f51f398d5855 100644 (file)
@@ -68,6 +68,6 @@ def py_make_scanner(context):
         finally:
             memo.clear()
 
-    return _scan_once
+    return scan_once
 
 make_scanner = c_make_scanner or py_make_scanner
index d84ef7da24463bd6eec22b22c4eccf7bf72a210e..fdb9e62124ece1f3c0446088d0b8fc7f130ae9bb 100644 (file)
@@ -58,7 +58,9 @@ class TestDecode:
     def test_keys_reuse(self):
         s = '[{"a_key": 1, "b_\xe9": 2}, {"a_key": 3, "b_\xe9": 4}]'
         self.check_keys_reuse(s, self.loads)
-        self.check_keys_reuse(s, self.json.decoder.JSONDecoder().decode)
+        decoder = self.json.decoder.JSONDecoder()
+        self.check_keys_reuse(s, decoder.decode)
+        self.assertFalse(decoder.memo)
 
     def test_extra_data(self):
         s = '[1, 2, 3]5'
diff --git a/Misc/NEWS.d/next/Library/2018-05-22-13-05-12.bpo-30877.JZEGjI.rst b/Misc/NEWS.d/next/Library/2018-05-22-13-05-12.bpo-30877.JZEGjI.rst
new file mode 100644 (file)
index 0000000..4be0fae
--- /dev/null
@@ -0,0 +1,3 @@
+Fixed a bug in the Python implementation of the JSON decoder that prevented
+the cache of parsed strings from clearing after finishing the decoding.
+Based on patch by c-fos.