inspect.iscode -> hasattr for now until we write a cross-version iscode

This commit is contained in:
rocky
2015-12-29 17:05:48 -05:00
parent 34841abe14
commit 116263dd8c
3 changed files with 6 additions and 6 deletions

View File

@@ -92,7 +92,7 @@ def get_python_parser(version, debug_parser):
def python_parser(version, co, out=sys.stdout, showasm=False, def python_parser(version, co, out=sys.stdout, showasm=False,
parser_debug=PARSER_DEFAULT_DEBUG): parser_debug=PARSER_DEFAULT_DEBUG):
import inspect import inspect
assert inspect.iscode(co) assert hasattr(co, 'co_name')
from uncompyle6.scanner import get_scanner from uncompyle6.scanner import get_scanner
scanner = get_scanner(version) scanner = get_scanner(version)
tokens, customize = scanner.disassemble(co) tokens, customize = scanner.disassemble(co)

View File

@@ -98,7 +98,7 @@ class Scanner34(scan3.Scanner3):
# other than LOAD_CONST, but we'll start out with just this for now. # other than LOAD_CONST, but we'll start out with just this for now.
if opname in ['LOAD_CONST']: if opname in ['LOAD_CONST']:
const = inst.argval const = inst.argval
if inspect.iscode(const): if hasattr(const, 'co_name')):
if const.co_name == '<lambda>': if const.co_name == '<lambda>':
opname = 'LOAD_LAMBDA' opname = 'LOAD_LAMBDA'
elif const.co_name == '<genexpr>': elif const.co_name == '<genexpr>':

View File

@@ -138,8 +138,8 @@ def cmp_code_objects(version, code_obj1, code_obj2, name=''):
This is the main part of this module. This is the main part of this module.
""" """
# print code_obj1, type(code_obj2) # print code_obj1, type(code_obj2)
assert inspect.iscode(code_obj1) assert code_obj1, hasattr('co_name')
assert inspect.iscode(code_obj2) assert code_obj2, hasattr('co_name')
# print dir(code_obj1) # print dir(code_obj1)
if isinstance(code_obj1, object): if isinstance(code_obj1, object):
# new style classes (Python 2.2) # new style classes (Python 2.2)
@@ -307,8 +307,8 @@ def cmp_code_objects(version, code_obj1, code_obj2, name=''):
elif member == 'co_consts': elif member == 'co_consts':
# partial optimization can make the co_consts look different, # partial optimization can make the co_consts look different,
# so we'll just compare the code consts # so we'll just compare the code consts
codes1 = ( c for c in code_obj1.co_consts if inspect.iscode(c) ) codes1 = ( c for c in code_obj1.co_consts if hasattr(c, 'co_consts') )
codes2 = ( c for c in code_obj2.co_consts if inspect.iscode(c) ) codes2 = ( c for c in code_obj2.co_consts if hasattr(c, 'co_consts') )
for c1, c2 in zip(codes1, codes2): for c1, c2 in zip(codes1, codes2):
cmp_code_objects(version, c1, c2, name=name) cmp_code_objects(version, c1, c2, name=name)