From e2732d3e66eba9ec13f9d55c499f2437ead552db Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 11 Mar 2018 11:07:06 +0200 Subject: bpo-32970: Improve disassembly of the MAKE_FUNCTION instruction. (GH-5937) --- Lib/dis.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Lib/dis.py') diff --git a/Lib/dis.py b/Lib/dis.py index 90ddf4f336..b2b0003203 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<