[Python-checkins] bpo-30877: Fix clearing a cache in the the JSON decoder. (GH-7048)

Miss Islington (bot) webhook-mailer at python.org
Tue May 22 09:26:53 EDT 2018


https://github.com/python/cpython/commit/2baee0aa77055755ac50e92e64bbccfea4108621
commit: 2baee0aa77055755ac50e92e64bbccfea4108621
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-05-22T06:26:43-07:00
summary:

bpo-30877: Fix clearing a cache in the the JSON decoder. (GH-7048)

(cherry picked from commit ae00fb1d4f38ea1803b10d798564740adcdad63e)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
A Misc/NEWS.d/next/Library/2018-05-22-13-05-12.bpo-30877.JZEGjI.rst
M Lib/json/scanner.py
M Lib/test/test_json/test_decode.py

diff --git a/Lib/json/scanner.py b/Lib/json/scanner.py
index 86426cde1a72..6e19ca633168 100644
--- a/Lib/json/scanner.py
+++ b/Lib/json/scanner.py
@@ -68,6 +68,6 @@ def scan_once(string, idx):
         finally:
             memo.clear()
 
-    return _scan_once
+    return scan_once
 
 make_scanner = c_make_scanner or py_make_scanner
diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py
index 7e568be40974..738f109fe68d 100644
--- a/Lib/test/test_json/test_decode.py
+++ b/Lib/test/test_json/test_decode.py
@@ -58,7 +58,9 @@ def check_keys_reuse(self, source, loads):
     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
index 000000000000..4be0fae4ecb6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-05-22-13-05-12.bpo-30877.JZEGjI.rst
@@ -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.



More information about the Python-checkins mailing list