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

dis failed to parse function that has only annotations #86728

Closed
uriyyo opened this issue Dec 3, 2020 · 4 comments
Closed

dis failed to parse function that has only annotations #86728

uriyyo opened this issue Dec 3, 2020 · 4 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@uriyyo
Copy link
Member

uriyyo commented Dec 3, 2020

BPO 42562
Nosy @markshannon, @uriyyo
PRs
  • bpo-42562: Fix issue when dis failed to parse function that has no line numbers #23632
  • 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 2020-12-04.15:23:45.704>
    created_at = <Date 2020-12-03.20:38:17.926>
    labels = ['type-bug', 'library', '3.10']
    title = 'dis failed to parse function that has only annotations'
    updated_at = <Date 2020-12-04.15:23:45.703>
    user = 'https://github.com/uriyyo'

    bugs.python.org fields:

    activity = <Date 2020-12-04.15:23:45.703>
    actor = 'Mark.Shannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-12-04.15:23:45.704>
    closer = 'Mark.Shannon'
    components = ['Library (Lib)']
    creation = <Date 2020-12-03.20:38:17.926>
    creator = 'uriyyo'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42562
    keywords = ['patch']
    message_count = 4.0
    messages = ['382453', '382477', '382491', '382493']
    nosy_count = 2.0
    nosy_names = ['Mark.Shannon', 'uriyyo']
    pr_nums = ['23632']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42562'
    versions = ['Python 3.10']

    @uriyyo
    Copy link
    Member Author

    uriyyo commented Dec 3, 2020

    dis module failed when trying to parse function that has only annotations at the function body:

    def foo():
        a: int
    

    Failed with stacktrace:

      1           0 LOAD_CONST               0 (<code object foo at 0x10847ebe0, file "test.py", line 1>)
                  2 LOAD_CONST               1 ('foo')
                  4 MAKE_FUNCTION            0
                  6 STORE_NAME               0 (foo)
                  8 LOAD_CONST               2 (None)
                 10 RETURN_VALUE
    
    Disassembly of <code object foo at 0x10847ebe0, file "test.py", line 1>:
    Traceback (most recent call last):
      File "/Users/yuriikarabas/my-projects/temp-cpython/Lib/runpy.py", line 197, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/Users/yuriikarabas/my-projects/temp-cpython/Lib/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/Users/yuriikarabas/my-projects/temp-cpython/Lib/dis.py", line 536, in <module>
        _test()
      File "/Users/yuriikarabas/my-projects/temp-cpython/Lib/dis.py", line 533, in _test
        dis(code)
      File "/Users/yuriikarabas/my-projects/temp-cpython/Lib/dis.py", line 79, in dis
        _disassemble_recursive(x, file=file, depth=depth)
      File "/Users/yuriikarabas/my-projects/temp-cpython/Lib/dis.py", line 381, in _disassemble_recursive
        _disassemble_recursive(x, file=file, depth=depth)
      File "/Users/yuriikarabas/my-projects/temp-cpython/Lib/dis.py", line 373, in _disassemble_recursive
        disassemble(co, file=file)
      File "/Users/yuriikarabas/my-projects/temp-cpython/Lib/dis.py", line 369, in disassemble
        _disassemble_bytes(co.co_code, lasti, co.co_varnames, co.co_names,
      File "/Users/yuriikarabas/my-projects/temp-cpython/Lib/dis.py", line 389, in _disassemble_bytes
        maxlineno = max(linestarts.values()) + line_offset
    ValueError: max() arg is an empty sequence
    

    @uriyyo uriyyo added 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 3, 2020
    @markshannon
    Copy link
    Member

    There are two issues here.

    1. The compiler is not following PEP-626 for functions with no executable code
    2. dis is not robust in the case that there are no line numbers.

    I want to fix 1. first, then 2.

    @markshannon
    Copy link
    Member

    New changeset f24b810 by Yurii Karabas in branch 'master':
    bpo-42562: Fix issue when dis failed to parse function that has no line numbers (GH-23632)
    f24b810

    @markshannon
    Copy link
    Member

    Thanks Yurii

    @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.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants