Python 2.7 set comprehension bug

This commit is contained in:
rocky
2016-07-27 08:36:33 -04:00
parent 2523b340cd
commit 5e801b5d74
2 changed files with 7 additions and 7 deletions

View File

@@ -1202,7 +1202,7 @@ class SourceWalker(GenericASTTraversal, object):
self.write('{') self.write('{')
if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']: if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']:
self.comprehension_walk3(node, 1, 0) self.comprehension_walk3(node, 1, 0)
elif node[0].type == 'load_closure': elif node[0].type == 'load_closure' and self.version >= 3.0:
self.setcomprehension_walk3(node, collection_index=4) self.setcomprehension_walk3(node, collection_index=4)
else: else:
self.comprehension_walk(node, iter_index=4) self.comprehension_walk(node, iter_index=4)

View File

@@ -1,6 +1,6 @@
# #
# (C) Copyright 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com> # (C) Copyright 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
# (C) Copyright 2015 by Rocky Bernstein # (C) Copyright 2015-2016 by Rocky Bernstein
# #
""" """
byte-code verification byte-code verification
@@ -132,7 +132,7 @@ class CmpErrorMember(VerifyCmpError):
# these members are ignored # these members are ignored
__IGNORE_CODE_MEMBERS__ = ['co_filename', 'co_firstlineno', 'co_lnotab', 'co_stacksize', 'co_names'] __IGNORE_CODE_MEMBERS__ = ['co_filename', 'co_firstlineno', 'co_lnotab', 'co_stacksize', 'co_names']
def cmp_code_objects(version, code_obj1, code_obj2, name='', is_pypy=False): def cmp_code_objects(version, is_pypy, code_obj1, code_obj2, name=''):
""" """
Compare two code-objects. Compare two code-objects.
@@ -195,7 +195,7 @@ def cmp_code_objects(version, code_obj1, code_obj2, name='', is_pypy=False):
elif version == 2.7: elif version == 2.7:
if is_pypy: if is_pypy:
import uncompyle6.scanners.pypy27 as scan import uncompyle6.scanners.pypy27 as scan
scanner = scan.ScannerPyPy27() scanner = scan.ScannerPyPy27(show_asm=False)
else: else:
import uncompyle6.scanners.scanner27 as scan import uncompyle6.scanners.scanner27 as scan
scanner = scan.Scanner27() scanner = scan.Scanner27()
@@ -331,7 +331,7 @@ def cmp_code_objects(version, code_obj1, code_obj2, name='', is_pypy=False):
codes2 = ( c for c in code_obj2.co_consts if hasattr(c, 'co_consts') ) 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, is_pypy, c1, c2, name=name)
else: else:
# all other members must be equal # all other members must be equal
if getattr(code_obj1, member) != getattr(code_obj2, member): if getattr(code_obj1, member) != getattr(code_obj2, member):
@@ -373,14 +373,14 @@ def compare_code_with_srcfile(pyc_filename, src_filename):
% (PYTHON_MAGIC_INT, magic_int)) % (PYTHON_MAGIC_INT, magic_int))
return msg return msg
code_obj2 = load_file(src_filename) code_obj2 = load_file(src_filename)
cmp_code_objects(version, code_obj1, code_obj2) cmp_code_objects(version, is_pypy, code_obj1, code_obj2)
return None return None
def compare_files(pyc_filename1, pyc_filename2): def compare_files(pyc_filename1, pyc_filename2):
"""Compare two .pyc files.""" """Compare two .pyc files."""
version, timestamp, magic_int1, code_obj1, is_pypy = uncompyle6.load_module(pyc_filename1) version, timestamp, magic_int1, code_obj1, is_pypy = uncompyle6.load_module(pyc_filename1)
version, timestamp, magic_int2, code_obj2, is_pypy = uncompyle6.load_module(pyc_filename2) version, timestamp, magic_int2, code_obj2, is_pypy = uncompyle6.load_module(pyc_filename2)
cmp_code_objects(version, code_obj1, code_obj2) cmp_code_objects(version, is_pypy, code_obj1, code_obj2)
if __name__ == '__main__': if __name__ == '__main__':
t1 = Token('LOAD_CONST', None, 'code_object _expandLang', 52) t1 = Token('LOAD_CONST', None, 'code_object _expandLang', 52)