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.

classification
Title: `Dis` module doesn't know how to disassemble async generator or coroutine objects
Type: enhancement Stage: resolved
Components: Extension Modules Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mariatta, ncoghlan, serhiy.storchaka, syncosmic
Priority: normal Keywords:

Created on 2017-08-11 15:21 by syncosmic, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3077 merged syncosmic, 2017-08-11 19:00
Messages (8)
msg300167 - (view) Author: syncosmic (syncosmic) * Date: 2017-08-11 15:21
Issue 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.
msg300184 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-08-11 22:32
Adding Serhiy and Nick who worked on these parts of CPython.
msg300188 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-08-12 04:36
Is this a bug fix or a new feature? Adding support of generators in issue21947 was a new feature and was not backported to older versions.
msg300194 - (view) Author: syncosmic (syncosmic) * Date: 2017-08-12 10:39
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 issue21947 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.
msg300200 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2017-08-12 15:18
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).
msg300207 - (view) Author: syncosmic (syncosmic) * Date: 2017-08-12 21:33
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!
msg300470 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2017-08-18 02:29
New changeset fe2b56ab9212c1cf19c48b848fa60f7f201c366f by Nick Coghlan (syncosmic) in branch 'master':
bpo-31183: `dis` now handles coroutines & async generators (GH-3077)
https://github.com/python/cpython/commit/fe2b56ab9212c1cf19c48b848fa60f7f201c366f
msg300579 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2017-08-19 11:09
Thanks for the patch!

Issue 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).
History
Date User Action Args
2022-04-11 14:58:50adminsetgithub: 75366
2017-08-19 11:09:37ncoghlansetmessages: + msg300579
2017-08-19 11:07:30ncoghlansetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-08-18 02:29:23ncoghlansetmessages: + msg300470
2017-08-12 21:33:48syncosmicsetmessages: + msg300207
2017-08-12 15:18:14ncoghlansetmessages: + msg300200
versions: - Python 3.6
2017-08-12 10:39:17syncosmicsetmessages: + msg300194
2017-08-12 04:36:17serhiy.storchakasetmessages: + msg300188
2017-08-11 22:32:59Mariattasetnosy: + Mariatta, serhiy.storchaka, ncoghlan

messages: + msg300184
stage: patch review
2017-08-11 19:00:07syncosmicsetpull_requests: + pull_request3114
2017-08-11 15:21:31syncosmiccreate