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: dis failed to parse function that has only annotations
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, uriyyo
Priority: normal Keywords: patch

Created on 2020-12-03 20:38 by uriyyo, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23632 merged uriyyo, 2020-12-03 20:43
Messages (4)
msg382453 - (view) Author: Yurii Karabas (uriyyo) * (Python triager) Date: 2020-12-03 20:38
`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
```
msg382477 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-12-04 11:16
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.
msg382491 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-12-04 15:21
New changeset f24b8101a01fa98b1e3ec042ba896aeb4c24d4bc by Yurii Karabas in branch 'master':
bpo-42562: Fix issue when dis failed to parse function that has no line numbers (GH-23632)
https://github.com/python/cpython/commit/f24b8101a01fa98b1e3ec042ba896aeb4c24d4bc
msg382493 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-12-04 15:23
Thanks Yurii
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86728
2020-12-04 15:23:45Mark.Shannonsetstatus: open -> closed
resolution: fixed
messages: + msg382493

stage: patch review -> resolved
2020-12-04 15:21:03Mark.Shannonsetmessages: + msg382491
2020-12-04 11:16:01Mark.Shannonsetmessages: + msg382477
2020-12-03 20:47:49serhiy.storchakasetnosy: + Mark.Shannon
2020-12-03 20:43:26uriyyosetkeywords: + patch
stage: patch review
pull_requests: + pull_request22501
2020-12-03 20:38:17uriyyocreate