You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
A couple more 2.6 (and below) bugs fixed
* Detect "return None" inside if statement * another case of triple ==, ==, == scanner2.py: detect_structure: descriminate more on parent type
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -10,3 +10,20 @@ def __iter__(self):
|
||||
i += 1
|
||||
except IndexError:
|
||||
return
|
||||
|
||||
|
||||
# From 2.6 bsddb/__init.py
|
||||
# Bug is return None in a generator inside
|
||||
# an if.
|
||||
def iteritems(self):
|
||||
if not self.db:
|
||||
return
|
||||
try:
|
||||
try:
|
||||
yield self.kv
|
||||
except:
|
||||
# the database was modified during iteration. abort.
|
||||
pass
|
||||
except:
|
||||
self._in_iter -= 1
|
||||
raise
|
||||
|
@@ -713,9 +713,15 @@ class Scanner2(scan.Scanner):
|
||||
self.fixed_jumps[pos] = fix or match[-1]
|
||||
return
|
||||
else:
|
||||
if self.version < 2.7 and parent['type'] == 'root':
|
||||
if (self.version < 2.7
|
||||
and parent['type'] in ('root', 'for-loop', 'if-then',
|
||||
'if-else', 'try')):
|
||||
self.fixed_jumps[pos] = rtarget
|
||||
else:
|
||||
# note test for < 2.7 might be superflous although informative
|
||||
# for 2.7 a different branch is taken and the below code is handled
|
||||
# under: elif op in self.pop_jump_if_or_pop
|
||||
# below
|
||||
self.fixed_jumps[pos] = match[-1]
|
||||
return
|
||||
else: # op != self.opc.PJIT
|
||||
|
@@ -774,7 +774,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
def is_return_none(self, node):
|
||||
# Is there a better way?
|
||||
ret = (node == 'return_stmt'
|
||||
ret = (node in ('return_stmt', 'return_if_stmt')
|
||||
and node[0] == 'ret_expr'
|
||||
and node[0][0] == 'expr'
|
||||
and node[0][0][0] == 'LOAD_CONST'
|
||||
@@ -809,7 +809,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.prune()
|
||||
else:
|
||||
self.write(self.indent, 'return')
|
||||
if self.return_none or node != AST('return_stmt', [AST('ret_expr', [NONE]), Token('RETURN_END_IF')]):
|
||||
if self.return_none or not self.is_return_none(node):
|
||||
self.write(' ')
|
||||
self.preorder(node[0])
|
||||
self.println()
|
||||
|
Reference in New Issue
Block a user