diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index c0eb347cc..e46d4a738 100644 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -184,8 +184,10 @@ def bound_collection_from_tokens(self, tokens, t, i, collection_type): for j in range(collection_start, i): if tokens[j] == "LOAD_CONST": opname = "ADD_VALUE" + op_type = "const" else: opname = "ADD_VALUE_VAR" + op_type = "name" new_tokens.append( Token( opname=opname, @@ -196,6 +198,7 @@ def bound_collection_from_tokens(self, tokens, t, i, collection_type): linestart=tokens[j].linestart, opc=self.opc, has_extended_arg=False, + optype=op_type ) ) new_tokens.append( @@ -208,6 +211,7 @@ def bound_collection_from_tokens(self, tokens, t, i, collection_type): linestart=t.linestart, opc=t.opc, has_extended_arg=False, + optype="vargs", ) ) return new_tokens diff --git a/uncompyle6/scanners/scanner2.py b/uncompyle6/scanners/scanner2.py index f42676e39..f5495b4f9 100644 --- a/uncompyle6/scanners/scanner2.py +++ b/uncompyle6/scanners/scanner2.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015-2024 by Rocky Bernstein +# Copyright (c) 2015-2025 by Rocky Bernstein # Copyright (c) 2005 by Dan Pascu # Copyright (c) 2000-2002 by hartmut Goebel # @@ -39,7 +39,7 @@ from sys import intern from xdis import code2num, instruction_size, iscode, op_has_argument -from xdis.bytecode import _get_const_info +from xdis.bytecode import _get_const_info, get_optype from uncompyle6.scanner import Scanner, Token @@ -304,6 +304,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None): op = self.code[offset] op_name = self.op_name(op) + op_type = get_optype(op, self.opc) oparg = None pattr = None @@ -470,7 +471,15 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None): if offset not in replace: new_tokens.append( Token( - op_name, oparg, pattr, offset, linestart, op, has_arg, self.opc + op_name, + oparg, + pattr, + offset, + linestart, + op, + has_arg, + self.opc, + optype=op_type, ) ) else: @@ -484,6 +493,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None): op, has_arg, self.opc, + optype=op_type, ) ) pass diff --git a/uncompyle6/semantics/n_actions.py b/uncompyle6/semantics/n_actions.py index a15d34fc9..9234cea0f 100644 --- a/uncompyle6/semantics/n_actions.py +++ b/uncompyle6/semantics/n_actions.py @@ -275,8 +275,8 @@ def n_const_list(self, node: SyntaxTree): if elem == "ADD_VALUE": if elem.optype in ("local", "name"): value = elem.attr - elif elem.optype == "const" and not isinstance(elem.attr, str): - value = elem.attr + elif elem.optype == "const": + value = elem.pattr else: value = "%s" % repr(elem.attr) else: