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.

Author laike9m
Recipients laike9m, serhiy.storchaka
Date 2020-03-31.06:33:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1585636419.17.0.745722185034.issue40122@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-03-31 06:33:39laike9msetrecipients: + laike9m, serhiy.storchaka
2020-03-31 06:33:39laike9msetmessageid: <1585636419.17.0.745722185034.issue40122@roundup.psfhosted.org>
2020-03-31 06:33:39laike9mlinkissue40122 messages
2020-03-31 06:33:38laike9mcreate