diff options
author | syncosmic <gc@syncosmic.io> | 2017-08-18 02:29:21 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2017-08-18 02:29:21 (GMT) |
commit | fe2b56ab9212c1cf19c48b848fa60f7f201c366f (patch) | |
tree | d16493fb8cc7ff1f7e947011e65670d6d8e5e425 /Doc | |
parent | 82aff62462e65077a6614b466c986f93a601c33d (diff) | |
download | cpython-fe2b56ab9212c1cf19c48b848fa60f7f201c366f.zip cpython-fe2b56ab9212c1cf19c48b848fa60f7f201c366f.tar.gz cpython-fe2b56ab9212c1cf19c48b848fa60f7f201c366f.tar.bz2 |
bpo-31183: `dis` now handles coroutines & async generators (GH-3077)
Coroutines and async generators use a distinct attribute name for their
code objects, so this updates the `dis` module to correctly disassemble
objects with those attributes.
Due to the increase in the test module length, it also fixes some latent
defects in the tests related to how the displayed source line numbers
are extracted.
https://bugs.python.org/issue31230 is a follow-up issue suggesting we
may want to solve this a different way, by instead giving all these object
types a common `__code__` attribute, avoiding the need for special
casing in the `dis` module.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/dis.rst | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index bc32380..7b7c84d 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -53,8 +53,9 @@ code. .. class:: Bytecode(x, *, first_line=None, current_offset=None) - Analyse the bytecode corresponding to a function, generator, method, string - of source code, or a code object (as returned by :func:`compile`). + Analyse the bytecode corresponding to a function, generator, asynchronous + generator, coroutine, method, string of source code, or a code object (as + returned by :func:`compile`). This is a convenience wrapper around many of the functions listed below, most notably :func:`get_instructions`, as iterating over a :class:`Bytecode` @@ -92,6 +93,9 @@ code. Return a formatted multi-line string with detailed information about the code object, like :func:`code_info`. + .. versionchanged:: 3.7 + This can now handle coroutine and asynchronous generator objects. + Example:: >>> bytecode = dis.Bytecode(myfunc) @@ -114,7 +118,8 @@ operation is being performed, so the intermediate analysis object isn't useful: .. function:: code_info(x) Return a formatted multi-line string with detailed code object information - for the supplied function, generator, method, source code string or code object. + for the supplied function, generator, asynchronous generator, coroutine, + method, source code string or code object. Note that the exact contents of code info strings are highly implementation dependent and they may change arbitrarily across Python VMs or Python @@ -122,6 +127,9 @@ operation is being performed, so the intermediate analysis object isn't useful: .. versionadded:: 3.2 + .. versionchanged:: 3.7 + This can now handle coroutine and asynchronous generator objects. + .. function:: show_code(x, *, file=None) @@ -141,12 +149,13 @@ operation is being performed, so the intermediate analysis object isn't useful: .. function:: dis(x=None, *, file=None, depth=None) Disassemble the *x* object. *x* can denote either a module, a class, a - method, a function, a generator, a code object, a string of source code or - a byte sequence of raw bytecode. For a module, it disassembles all functions. - For a class, it disassembles all methods (including class and static methods). - For a code object or sequence of raw bytecode, it prints one line per bytecode - instruction. It also recursively disassembles nested code objects (the code - of comprehensions, generator expressions and nested functions, and the code + method, a function, a generator, an asynchronous generator, a couroutine, + a code object, a string of source code or a byte sequence of raw bytecode. + For a module, it disassembles all functions. For a class, it disassembles + all methods (including class and static methods). For a code object or + sequence of raw bytecode, it prints one line per bytecode instruction. + It also recursively disassembles nested code objects (the code of + comprehensions, generator expressions and nested functions, and the code used for building nested classes). Strings are first compiled to code objects with the :func:`compile` built-in function before being disassembled. If no object is provided, this @@ -164,6 +173,9 @@ operation is being performed, so the intermediate analysis object isn't useful: .. versionchanged:: 3.7 Implemented recursive disassembling and added *depth* parameter. + .. versionchanged:: 3.7 + This can now handle coroutine and asynchronous generator objects. + .. function:: distb(tb=None, *, file=None) |