New submission from laike9m <laik...@gmail.com>:

The documentation of dis.findlabels says:

> dis.findlabels(code)
> Detect all offsets in the code object code which are jump targets, and return 
> a list of these offsets.

But the implementation actually expects a raw compiled bytecode.

>>> def f():pass

>>> dis.findlabels(f.__code__)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/laike9m/.pyenv/versions/3.7.4/lib/python3.7/dis.py", line 424, 
in findlabels
    for offset, op, arg in _unpack_opargs(code):
  File "/Users/laike9m/.pyenv/versions/3.7.4/lib/python3.7/dis.py", line 408, 
in _unpack_opargs
    for i in range(0, len(code), 2):
TypeError: object of type 'code' has no len()

>>> dis.findlabels(f.__code__.co_code)
[]

Since the other functions in the dis module all accept a code object rather 
than compiled code, I would suggest change the code instead of documentation.

Plus, this function does not seem to be tested anywhere. I can make a PR if 
this issue is confirmed.

----------
components: Library (Lib)
messages: 365367
nosy: laike9m, serhiy.storchaka
priority: normal
severity: normal
status: open
title: The implementation and documentation of "dis.findlables" don't match
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40122>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to