X Tutup
Skip to content

Commit 09f6286

Browse files
committed
Fix 3.x generator bug...
found by Daniel Brandburn. See moagstar@af61622
1 parent 95bc1a7 commit 09f6286

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed
508 Bytes
Binary file not shown.
430 Bytes
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Had bug in Python 3.x
2+
3+
# Should see (Python 2.x and 3.x:
4+
# get_iter ::= expr GET_ITER
5+
# expr ::= get_iter
6+
# _for ::= GET_ITER FOR_ITER
7+
# designator ::= STORE_FAST
8+
# expr ::= LOAD_FAST
9+
# yield ::= expr YIELD_VALUE
10+
# expr ::= yield
11+
# gen_comp_body ::= expr YIELD_VALUE POP_TOP
12+
# comp_body ::= gen_comp_body
13+
# comp_iter ::= comp_body
14+
# comp_for ::= expr _for designator comp_iter JUMP_BACK
15+
# comp_iter ::= comp_for
16+
# genexpr_func ::= LOAD_FAST FOR_ITER designator comp_iter JUMP_BACK
17+
18+
def multi_genexpr(blog_posts):
19+
20+
return (
21+
entry
22+
for blog_post in blog_posts
23+
for entry in blog_post.entry_set
24+
)

uncompyle6/parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ def p_setcomp(self, args):
288288
289289
comp_if ::= expr jmp_false comp_iter
290290
comp_ifnot ::= expr jmp_true comp_iter
291+
292+
comp_for ::= expr _for designator comp_iter JUMP_BACK
291293
"""
292294

293295
def p_expr(self, args):

uncompyle6/parsers/parse2.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ def p_list_comprehension2(self, args):
3636
list_for ::= expr _for designator list_iter JUMP_BACK
3737
"""
3838

39-
def p_setcomp2(self, args):
40-
'''
41-
# This is different in python3 - should it be?
42-
comp_for ::= expr _for designator comp_iter JUMP_BACK
43-
'''
44-
4539
def p_print(self, args):
4640
'''
4741
stmt ::= print_items_stmt

uncompyle6/parsers/parse3.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ def p_list_comprehension3(self, args):
5858

5959
def p_setcomp3(self, args):
6060
"""
61-
# This is different in Python 2 - should it be?
62-
comp_for ::= expr _for designator comp_iter JUMP_ABSOLUTE
63-
64-
# See also common Python p_setcomp
61+
# Does this also happen in Python 2?
62+
# If so, adjust p_setcomp in parser.py
63+
comp_for ::= expr _for designator comp_iter JUMP_BACK
6564
"""
6665

6766
def p_grammar(self, args):

0 commit comments

Comments
 (0)
X Tutup