summaryrefslogtreecommitdiffstats
path: root/Lib/dis.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2014-07-25 13:02:56 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2014-07-25 13:02:56 (GMT)
commitefd5df9e5267fd337cde95b0dec319ea59187bf4 (patch)
treeaa20c9a774303b891ac047721b8e036e94988578 /Lib/dis.py
parentd0d64cfb59dda1b82e4ec05160f20316be75760d (diff)
downloadcpython-efd5df9e5267fd337cde95b0dec319ea59187bf4.zip
cpython-efd5df9e5267fd337cde95b0dec319ea59187bf4.tar.gz
cpython-efd5df9e5267fd337cde95b0dec319ea59187bf4.tar.bz2
Issue #21947: handle generator-iterator objects in dis
Patch by Clement Rouault.
Diffstat (limited to 'Lib/dis.py')
-rw-r--r--Lib/dis.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/dis.py b/Lib/dis.py
index 81cbe7f..d215bc5 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -29,7 +29,7 @@ def _try_compile(source, name):
return c
def dis(x=None, *, file=None):
- """Disassemble classes, methods, functions, or code.
+ """Disassemble classes, methods, functions, generators, or code.
With no argument, disassemble the last traceback.
@@ -41,6 +41,8 @@ def dis(x=None, *, file=None):
x = x.__func__
if hasattr(x, '__code__'): # Function
x = x.__code__
+ if hasattr(x, 'gi_code'): # Generator
+ x = x.gi_code
if hasattr(x, '__dict__'): # Class or module
items = sorted(x.__dict__.items())
for name, x1 in items:
@@ -99,11 +101,13 @@ def pretty_flags(flags):
return ", ".join(names)
def _get_code_object(x):
- """Helper to handle methods, functions, strings and raw code objects"""
+ """Helper to handle methods, functions, generators, strings and raw code objects"""
if hasattr(x, '__func__'): # Method
x = x.__func__
if hasattr(x, '__code__'): # Function
x = x.__code__
+ if hasattr(x, 'gi_code'): # Generator
+ x = x.gi_code
if isinstance(x, str): # Source code
x = _try_compile(x, "<disassembly>")
if hasattr(x, 'co_code'): # Code object