Skip to content

bpo-40169: Make dis.findlabels() accept a code object#19356

Open
laike9m wants to merge 1 commit into
python:mainfrom
laike9m:findlabels_codeobject
Open

bpo-40169: Make dis.findlabels() accept a code object#19356
laike9m wants to merge 1 commit into
python:mainfrom
laike9m:findlabels_codeobject

Conversation

@laike9m

@laike9m laike9m commented Apr 4, 2020

Copy link
Copy Markdown
Contributor

https://bugs.python.org/issue40169

Reasoning:

  • The documentation of dis has always been "it accepts a code object".
  • To keep it consistent with the other APIs in the dis module, which all accept a code object instead of raw byte code string.

@laike9m

laike9m commented Apr 7, 2020

Copy link
Copy Markdown
Contributor Author

Kindly ping...@serhiy-storchaka

@remilapeyre remilapeyre left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @laike9m, thinks for improving dis! I don't think this is the correct change thought, dis.findlabels(f.__code__.co_code) used to work but does not anymore. I think a more appropriate change would be to handle both code object and byte code, a way would be:

    if hasattr(code, 'co_code'):
        code = code.co_code
    elif not isinstance(code, bytes):
        raise TypeError(...)

A test with jumpy.__code__.co_code would be great too!

@laike9m

laike9m commented Jun 9, 2020

Copy link
Copy Markdown
Contributor Author

Thanks Remi.

I know the function was intended to take a code object because the doc explicitly says that before I fixed it to match the current behavior.
77c623b

I can change the code as you suggested. Do I need to get @serhiy-storchaka's approve before making the change? Cause I assume he owns this part.

@remilapeyre

Copy link
Copy Markdown

I know the function was intended to take a code object because the doc explicitly says that before I fixed it to match the current behavior.
77c623b

Yes, but since it used to take bytes (even thought it was not documented that way) it means that users wrote code that way and they expect it to keep working. Breaking that would need a deprecation period.

I can change the code as you suggested. Do I need to get @serhiy-storchaka's approve before making the change? Cause I assume he owns this part.

As you wish, you will need his approval either way.

@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants