Skip to content

Commit 647248d

Browse files
committed
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
1 parent f4ac13e commit 647248d

5 files changed

Lines changed: 26 additions & 3 deletions

File tree

264 Bytes
Binary file not shown.
262 Bytes
Binary file not shown.

test/simple_source/bug26/07_generator_return.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,20 @@ def __iter__(self):
1010
i += 1
1111
except IndexError:
1212
return
13+
14+
15+
# From 2.6 bsddb/__init.py
16+
# Bug is return None in a generator inside
17+
# an if.
18+
def iteritems(self):
19+
if not self.db:
20+
return
21+
try:
22+
try:
23+
yield self.kv
24+
except:
25+
# the database was modified during iteration. abort.
26+
pass
27+
except:
28+
self._in_iter -= 1
29+
raise

uncompyle6/scanners/scanner2.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,9 +713,15 @@ def detect_structure(self, pos, op):
713713
self.fixed_jumps[pos] = fix or match[-1]
714714
return
715715
else:
716-
if self.version < 2.7 and parent['type'] == 'root':
716+
if (self.version < 2.7
717+
and parent['type'] in ('root', 'for-loop', 'if-then',
718+
'if-else', 'try')):
717719
self.fixed_jumps[pos] = rtarget
718720
else:
721+
# note test for < 2.7 might be superflous although informative
722+
# for 2.7 a different branch is taken and the below code is handled
723+
# under: elif op in self.pop_jump_if_or_pop
724+
# below
719725
self.fixed_jumps[pos] = match[-1]
720726
return
721727
else: # op != self.opc.PJIT

uncompyle6/semantics/pysource.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ def print_docstring(self, indent, docstring):
774774

775775
def is_return_none(self, node):
776776
# Is there a better way?
777-
ret = (node == 'return_stmt'
777+
ret = (node in ('return_stmt', 'return_if_stmt')
778778
and node[0] == 'ret_expr'
779779
and node[0][0] == 'expr'
780780
and node[0][0][0] == 'LOAD_CONST'
@@ -809,7 +809,7 @@ def n_return_if_stmt(self, node):
809809
self.prune()
810810
else:
811811
self.write(self.indent, 'return')
812-
if self.return_none or node != AST('return_stmt', [AST('ret_expr', [NONE]), Token('RETURN_END_IF')]):
812+
if self.return_none or not self.is_return_none(node):
813813
self.write(' ')
814814
self.preorder(node[0])
815815
self.println()

0 commit comments

Comments
 (0)