Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dis module doesn't know how to disassemble async generator or coroutine objects #75366

Closed
syncosmic mannequin opened this issue Aug 11, 2017 · 8 comments
Closed

Dis module doesn't know how to disassemble async generator or coroutine objects #75366

syncosmic mannequin opened this issue Aug 11, 2017 · 8 comments
Labels
3.7 (EOL) end of life extension-modules C modules in the Modules dir type-feature A feature request or enhancement

Comments

@syncosmic
Copy link
Mannequin

syncosmic mannequin commented Aug 11, 2017

BPO 31183
Nosy @ncoghlan, @serhiy-storchaka, @Mariatta, @syncosmic
PRs
  • fix bpo-31183: allowing dis to disassemble async generator and coroutine objects #3077
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-08-19.11:07:30.550>
    created_at = <Date 2017-08-11.15:21:31.458>
    labels = ['extension-modules', 'type-feature', '3.7']
    title = "`Dis` module doesn't know how to disassemble async generator or coroutine objects"
    updated_at = <Date 2017-08-19.11:09:37.757>
    user = 'https://github.com/syncosmic'

    bugs.python.org fields:

    activity = <Date 2017-08-19.11:09:37.757>
    actor = 'ncoghlan'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-08-19.11:07:30.550>
    closer = 'ncoghlan'
    components = ['Extension Modules']
    creation = <Date 2017-08-11.15:21:31.458>
    creator = 'syncosmic'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31183
    keywords = []
    message_count = 8.0
    messages = ['300167', '300184', '300188', '300194', '300200', '300207', '300470', '300579']
    nosy_count = 4.0
    nosy_names = ['ncoghlan', 'serhiy.storchaka', 'Mariatta', 'syncosmic']
    pr_nums = ['3077']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue31183'
    versions = ['Python 3.7']

    @syncosmic
    Copy link
    Mannequin Author

    syncosmic mannequin commented Aug 11, 2017

    bpo-21947 informed the dis module about the gi_code attribute, which stores code objects for generator objects. This allows inspection of generator objects, not just functions which return them. However, asynchronous generator objects use ag_code and coroutine objects use cr_code, so dis raises a TypeError on them. I'm making a pull request to extend the generator behavior to async generators and coroutines.

    Credit to Luciano Ramalho: I tripped over this at his (great) concurrency workshop at PyBay 2017 and he identified exactly what was happening and suggested a patch.

    @syncosmic syncosmic mannequin added 3.7 (EOL) end of life extension-modules C modules in the Modules dir type-feature A feature request or enhancement labels Aug 11, 2017
    @Mariatta
    Copy link
    Member

    Adding Serhiy and Nick who worked on these parts of CPython.

    @serhiy-storchaka
    Copy link
    Member

    Is this a bug fix or a new feature? Adding support of generators in bpo-21947 was a new feature and was not backported to older versions.

    @syncosmic
    Copy link
    Mannequin Author

    syncosmic mannequin commented Aug 12, 2017

    Hm--either/both? I encountered it as a bug ("dis works on my generator object and my async generator function, why does it break on my async generator object?") but strictly speaking it's a new feature (just as bpo-21947 was). To my mind, adding this level of indirection (finding the code object) for generators was a bit of a design decision but once it's in for generators it should be in for async generators and coroutines by analogy.

    @ncoghlan
    Copy link
    Contributor

    While I agree the line is blurry, extending automatic disassembly to cover new types is currently still considered a new feature in the dis module rather than a bug in the addition of those new types to the language.

    Whether or not that's the right policy, or if we should consider tweaking it so that oversights in dis and inspect are treated as bugs in the addition of affected types, would be a question for python-dev (fortunately, the new cherry-pick based workflow means the current PR review can proceed independently of that question).

    @syncosmic
    Copy link
    Mannequin Author

    syncosmic mannequin commented Aug 12, 2017

    Makes sense. I'll update the PR in a bit, and if anyone is hitting this repeatedly and thinks it should be added to 3.6 they can advocate for a policy change in the maintaining-consistency-with-previous-new-features corner case.

    Thanks, all!

    @ncoghlan
    Copy link
    Contributor

    New changeset fe2b56a by Nick Coghlan (syncosmic) in branch 'master':
    bpo-31183: dis now handles coroutines & async generators (GH-3077)
    fe2b56a

    @ncoghlan
    Copy link
    Contributor

    Thanks for the patch!

    bpo-31230 is a follow-up issue looking at whether or not we should define a general "__code__" attribute as a general purpose introspection protocol for disassembly support (amongst other generalisations of state introspection support for async operations).

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life extension-modules C modules in the Modules dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants