summaryrefslogtreecommitdiffstats
path: root/Lib/dis.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-03-11 09:07:06 (GMT)
committerGitHub <noreply@github.com>2018-03-11 09:07:06 (GMT)
commite2732d3e66eba9ec13f9d55c499f2437ead552db (patch)
tree010be14ab95b6e68ee25a9369496532a9aa2129c /Lib/dis.py
parent3f7e9aa2ef215917b9f1521441f67f4ecd33a1bc (diff)
downloadcpython-e2732d3e66eba9ec13f9d55c499f2437ead552db.zip
cpython-e2732d3e66eba9ec13f9d55c499f2437ead552db.tar.gz
cpython-e2732d3e66eba9ec13f9d55c499f2437ead552db.tar.bz2
bpo-32970: Improve disassembly of the MAKE_FUNCTION instruction. (GH-5937)
Diffstat (limited to 'Lib/dis.py')
-rw-r--r--Lib/dis.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/Lib/dis.py b/Lib/dis.py
index 90ddf4f..b2b0003 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -17,6 +17,15 @@ _have_code = (types.MethodType, types.FunctionType, types.CodeType,
classmethod, staticmethod, type)
FORMAT_VALUE = opmap['FORMAT_VALUE']
+FORMAT_VALUE_CONVERTERS = (
+ (None, ''),
+ (str, 'str'),
+ (repr, 'repr'),
+ (ascii, 'ascii'),
+)
+MAKE_FUNCTION = opmap['MAKE_FUNCTION']
+MAKE_FUNCTION_FLAGS = ('defaults', 'kwdefaults', 'annotations', 'closure')
+
def _try_compile(source, name):
"""Attempts to compile the given source, first as an expression and
@@ -339,12 +348,15 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
elif op in hasfree:
argval, argrepr = _get_name_info(arg, cells)
elif op == FORMAT_VALUE:
- argval = ((None, str, repr, ascii)[arg & 0x3], bool(arg & 0x4))
- argrepr = ('', 'str', 'repr', 'ascii')[arg & 0x3]
+ argval, argrepr = FORMAT_VALUE_CONVERTERS[arg & 0x3]
+ argval = (argval, bool(arg & 0x4))
if argval[1]:
if argrepr:
argrepr += ', '
argrepr += 'with format'
+ elif op == MAKE_FUNCTION:
+ argrepr = ', '.join(s for i, s in enumerate(MAKE_FUNCTION_FLAGS)
+ if arg & (1<<i))
yield Instruction(opname[op], op,
arg, argval, argrepr,
offset, starts_line, is_jump_target)