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.

Title: The implementation and documentation of "dis.findlables" don't match
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.9, Python 3.8, Python 3.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Manjusaka, docs@python, laike9m, miss-islington, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2020-03-31 06:33 by laike9m, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19274 merged laike9m, 2020-04-01 05:50
PR 19330 merged miss-islington, 2020-04-03 08:00
PR 19331 merged miss-islington, 2020-04-03 08:00
Messages (6)
msg365367 - (view) Author: laike9m (laike9m) * Date: 2020-03-31 06:33
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/", line 424, in findlabels
    for offset, op, arg in _unpack_opargs(code):
  File "/Users/laike9m/.pyenv/versions/3.7.4/lib/python3.7/", 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.
msg365374 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-03-31 10:43
dis.findlabels() always worked with a byte code. And the docstring correctly describes this.

I think this is a documentation issue. The documentation fix should be backported to all maintained Python versions.

If you want to make dis.findlabels() accepting a code object, it would be a new feature and it may be only added in future Python release (3.9). It needs a separate issue. In any case the documentation bug should be fixed in maintained versions.
msg365450 - (view) Author: laike9m (laike9m) * Date: 2020-04-01 05:52
I've created a PR to fix documentation.

I'll create a new issue for making the function accept a code object.
msg365678 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-03 08:00
New changeset b74468e233a5137ff518e61eff65ca2d8833e38a by laike9m in branch 'master':
bpo-40122: Updated documentation for dis.findlabels() (GH-19274)
msg365679 - (view) Author: miss-islington (miss-islington) Date: 2020-04-03 08:06
New changeset 00c779fd9c0a9e7586681a44e35607c1113b5014 by Miss Islington (bot) in branch '3.7':
bpo-40122: Updated documentation for dis.findlabels() (GH-19274)
msg365680 - (view) Author: miss-islington (miss-islington) Date: 2020-04-03 08:07
New changeset 77c623ba3d084e99d68c30f368bd7fbd7f175b60 by Miss Islington (bot) in branch '3.8':
bpo-40122: Updated documentation for dis.findlabels() (GH-19274)
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84303
2020-04-03 09:14:10serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-04-03 08:07:22miss-islingtonsetmessages: + msg365680
2020-04-03 08:06:15miss-islingtonsetmessages: + msg365679
2020-04-03 08:00:51miss-islingtonsetpull_requests: + pull_request18696
2020-04-03 08:00:44miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request18695
2020-04-03 08:00:36serhiy.storchakasetmessages: + msg365678
2020-04-01 05:52:53laike9msetmessages: + msg365450
2020-04-01 05:50:19laike9msetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request18629
2020-03-31 12:21:38vstinnersetnosy: - vstinner
2020-03-31 10:43:40serhiy.storchakasetassignee: docs@python
type: behavior
components: + Documentation, - Library (Lib)
versions: + Python 3.7, Python 3.8
nosy: + docs@python

messages: + msg365374
stage: needs patch
2020-03-31 06:55:02Manjusakasetnosy: + vstinner, Manjusaka
2020-03-31 06:33:39laike9mcreate