Skip to content
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

Closed
c-fos mannequin opened this issue Jul 8, 2017 · 7 comments
Closed

possibe typo in json/scanner.py #75060

c-fos mannequin opened this issue Jul 8, 2017 · 7 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@c-fos
Copy link
Mannequin

c-fos mannequin commented Jul 8, 2017

BPO 30877
Nosy @pitrou, @serhiy-storchaka, @c-fos, @miss-islington
PRs
  • bpo-30877 possible typo in json/scanner.py #2632
  • bpo-30877: Fix clearing a cache in the the JSON decoder. #7048
  • [3.7] bpo-30877: Fix clearing a cache in the the JSON decoder. (GH-7048) #7053
  • [3.6] bpo-30877: Fix clearing a cache in the the JSON decoder. (GH-7048) #7054
  • 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:

    assignee = None
    closed_at = <Date 2018-05-22.15:45:19.225>
    created_at = <Date 2017-07-08.06:48:08.510>
    labels = ['3.7', '3.8', 'type-feature', 'library']
    title = 'possibe typo in json/scanner.py'
    updated_at = <Date 2018-05-22.15:45:19.224>
    user = 'https://github.com/c-fos'

    bugs.python.org fields:

    activity = <Date 2018-05-22.15:45:19.224>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-05-22.15:45:19.225>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2017-07-08.06:48:08.510>
    creator = 'c-fos'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30877
    keywords = ['patch']
    message_count = 7.0
    messages = ['297945', '297949', '297951', '297952', '317267', '317274', '317277']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'serhiy.storchaka', 'c-fos', 'miss-islington']
    pr_nums = ['2632', '7048', '7053', '7054']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30877'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @c-fos
    Copy link
    Mannequin Author

    c-fos mannequin commented Jul 8, 2017

    Should "py_make_scanner" return "scan_once" function rather than "_scan_once"?

    @c-fos c-fos mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jul 8, 2017
    @serhiy-storchaka
    Copy link
    Member

    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?

    @c-fos
    Copy link
    Mannequin Author

    c-fos mannequin commented Jul 8, 2017

    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

    @c-fos
    Copy link
    Mannequin Author

    c-fos mannequin commented Jul 8, 2017

    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)

    @serhiy-storchaka
    Copy link
    Member

    Sorry for not fixing this issue earlier. The fix is trivial, but it needed tests. PR 7048 adds a simpler test.

    @serhiy-storchaka serhiy-storchaka added the 3.8 only security fixes label May 22, 2018
    @miss-islington
    Copy link
    Contributor

    New changeset 25fd6cc by Miss Islington (bot) in branch '3.7':
    bpo-30877: Fix clearing a cache in the the JSON decoder. (GH-7048)
    25fd6cc

    @miss-islington
    Copy link
    Contributor

    New changeset 2baee0a by Miss Islington (bot) in branch '3.6':
    bpo-30877: Fix clearing a cache in the the JSON decoder. (GH-7048)
    2baee0a

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants