]> 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:26:43 +0000 (06:26 -0700)
committerGitHub <noreply@github.com>
Tue, 22 May 2018 13:26:43 +0000 (06:26 -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 86426cde1a72c065f8dffcc8033747ca103e2515..6e19ca633168f6fb6752e6a92b419f96c88a78b2 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 7e568be40974cb64249310474add755247a736a5..738f109fe68deca9b10cc4ad7d853d8eba5b2923 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.