New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
possibe typo in json/scanner.py #75060
Comments
Should "py_make_scanner" return "scan_once" function rather than "_scan_once"? |
Good catch c-fos! The scan_once() wrapper was introduced in bpo-7451, but py_make_scanner() still returns unwrapped _scan_once(). Is it possible to write a test that catches this bug? |
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 |
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) |
Sorry for not fixing this issue earlier. The fix is trivial, but it needed tests. PR 7048 adds a simpler test. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: