This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: possibe typo in json/scanner.py
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: c-fos, miss-islington, pitrou, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-07-08 06:48 by c-fos, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2632 closed python-dev, 2017-07-08 06:48
PR 7048 merged serhiy.storchaka, 2018-05-22 10:08
PR 7053 merged miss-islington, 2018-05-22 11:56
PR 7054 merged miss-islington, 2018-05-22 11:57
Messages (7)
msg297945 - (view) Author: c-fos (c-fos) * Date: 2017-07-08 06:48
Should "py_make_scanner" return "scan_once" function rather than "_scan_once"?
msg297949 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-07-08 07:39
Good catch c-fos!

The scan_once() wrapper was introduced in issue7451, but py_make_scanner() still returns unwrapped _scan_once().

Is it possible to write a test that catches this bug?
msg297951 - (view) Author: c-fos (c-fos) * Date: 2017-07-08 08:40
The possible test:

import unittest
from json.decoder import JSONDecoder

class Memo_Test(unittest.TestCase):
    def test_for_empty_memo(self):
        json_str = '{"a": 1}'
        decoder = JSONDecoder()
        decoder.decode(json_str)
        self.assertEqual(decoder.memo, {})

suite = unittest.TestSuite()
suite.addTest(Memo_Test("test_for_empty_memo"))
runner = unittest.TextTestRunner()
runner.run(suite)

But it works only when _json import fails
msg297952 - (view) Author: c-fos (c-fos) * Date: 2017-07-08 09:20
Test independent from _json library:

import unittest
from json.decoder import JSONDecoder
from json.scanner import py_make_scanner

class Memo_Test(unittest.TestCase):
    def test_for_empty_memo(self):
        json_str = '{"a": 1}'
        decoder = JSONDecoder()
        decoder.scan_once = py_make_scanner(decoder)
        result = decoder.decode(json_str)
        self.assertEqual(result, {"a":1})
        self.assertEqual(decoder.memo, {})

suite = unittest.TestSuite()
suite.addTest(Memo_Test("test_for_empty_memo"))
runner = unittest.TextTestRunner()
runner.run(suite)
msg317267 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-22 10:11
Sorry for not fixing this issue earlier. The fix is trivial, but it needed tests. PR 7048 adds a simpler test.
msg317274 - (view) Author: miss-islington (miss-islington) Date: 2018-05-22 13:03
New changeset 25fd6cc5b0ad311bb771ae47ae8173417730bb6a by Miss Islington (bot) in branch '3.7':
bpo-30877: Fix clearing a cache in the the JSON decoder. (GH-7048)
https://github.com/python/cpython/commit/25fd6cc5b0ad311bb771ae47ae8173417730bb6a
msg317277 - (view) Author: miss-islington (miss-islington) Date: 2018-05-22 13:26
New changeset 2baee0aa77055755ac50e92e64bbccfea4108621 by Miss Islington (bot) in branch '3.6':
bpo-30877: Fix clearing a cache in the the JSON decoder. (GH-7048)
https://github.com/python/cpython/commit/2baee0aa77055755ac50e92e64bbccfea4108621
History
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 75060
2018-05-22 15:45:19serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-05-22 13:26:52miss-islingtonsetmessages: + msg317277
2018-05-22 13:03:20miss-islingtonsetnosy: + miss-islington
messages: + msg317274
2018-05-22 11:57:17miss-islingtonsetpull_requests: + pull_request6688
2018-05-22 11:56:25miss-islingtonsetpull_requests: + pull_request6687
2018-05-22 10:14:12serhiy.storchakalinkissue33596 superseder
2018-05-22 10:11:22serhiy.storchakasetmessages: + msg317267
versions: + Python 3.8, - Python 3.5
2018-05-22 10:08:53serhiy.storchakasetkeywords: + patch
pull_requests: + pull_request6685
2017-07-08 09:20:14c-fossetmessages: + msg297952
2017-07-08 08:40:42c-fossetmessages: + msg297951
2017-07-08 07:39:09serhiy.storchakasetversions: + Python 3.5, Python 3.6
nosy: + serhiy.storchaka, pitrou

messages: + msg297949

stage: patch review
2017-07-08 06:48:37python-devsetpull_requests: + pull_request2697
2017-07-08 06:48:08c-foscreate