Skip to content

Commit 830a2eb

Browse files
committed
Sync with decompyle3
1 parent e3be411 commit 830a2eb

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

uncompyle6/scanner.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
scanners, e.g. for Python 2.7 or 3.4.
2222
"""
2323

24+
from abc import ABC
2425
from array import array
2526
from collections import namedtuple
2627
from types import ModuleType
@@ -89,7 +90,7 @@ def long(num):
8990
CONST_COLLECTIONS = ("CONST_LIST", "CONST_SET", "CONST_DICT", "CONST_MAP")
9091

9192

92-
class Code(object):
93+
class Code:
9394
"""
9495
Class for representing code-objects.
9596
@@ -108,7 +109,7 @@ def __init__(self, co, scanner, classname=None, show_asm=None):
108109
self._tokens, self._customize = scanner.ingest(co, classname, show_asm=show_asm)
109110

110111

111-
class Scanner:
112+
class Scanner(ABC):
112113
def __init__(self, version: tuple, show_asm=None, is_pypy=False):
113114
self.version = version
114115
self.show_asm = show_asm
@@ -293,6 +294,12 @@ def is_jump_forward(self, offset: int) -> bool:
293294
return False
294295
return offset < self.get_target(offset)
295296

297+
def ingest(self, co, classname=None, code_objects={}, show_asm=None):
298+
"""
299+
Code to tokenize disassembly. Subclasses must implement this.
300+
"""
301+
raise NotImplementedError("This method should have been implemented")
302+
296303
def prev_offset(self, offset: int) -> int:
297304
return self.insts[self.offset2inst_index[offset] - 1].offset
298305

uncompyle6/scanners/scanner37.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def bound_collection_from_tokens(
5353
if collection_type == "CONST_DICT":
5454
# constant dictionaries work via BUILD_CONST_KEY_MAP and
5555
# handle the values() like sets and lists.
56-
# However the keys() are an LOAD_CONST of the keys.
56+
# However, the keys() are an LOAD_CONST of the keys.
5757
# adjust offset to account for this
5858
count += 1
5959

uncompyle6/scanners/scanner37base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,9 @@ def tokens_append(j, token):
266266
if (
267267
next_inst.opname == "LOAD_GLOBAL"
268268
and next_inst.argval == "AssertionError"
269-
and inst.argval
269+
and inst.argval is not None
270270
):
271-
raise_idx = self.offset2inst_index[self.prev_op[inst.argval]]
272-
raise_inst = self.insts[raise_idx]
271+
raise_inst = self.get_inst(self.prev_op[inst.argval])
273272
if raise_inst.opname.startswith("RAISE_VARARGS"):
274273
self.load_asserts.add(next_inst.offset)
275274
pass
@@ -286,7 +285,7 @@ def tokens_append(j, token):
286285
# some backward jumps, are turned into forward jumps to another
287286
# "extended arg" backward jump to the same location.
288287
if inst.opname == "JUMP_FORWARD":
289-
jump_inst = self.insts[self.offset2inst_index[inst.argval]]
288+
jump_inst = self.get_inst(inst.argval)
290289
if jump_inst.has_extended_arg and jump_inst.opname.startswith("JUMP"):
291290
# Create a combination of the jump-to instruction and
292291
# this one. Keep the position information of this instruction,

0 commit comments

Comments
 (0)