3.7+ "or" handling in listcomp

This commit is contained in:
rocky
2020-01-09 03:15:06 -05:00
parent 7c03cc466d
commit 7dee584a46
4 changed files with 14 additions and 0 deletions

View File

@@ -23,6 +23,17 @@ def columnize(l):
if not isinstance(l[i], str)]
assert [0, 2] == columnize([1, 'a', 2])
# From 3.7.6 _collections_abc.py
# Bug was handling "or" in listcomp
def count(values, x):
return sum(1 for v in values if v or x)
assert count([2, 2], False) == 2
assert count([], False) == 0
assert count([], True) == 0
assert count([2], True) == 1
assert count([0], False) == 0
# From 3.7 test_generators
# Bug was in handling the way list_if is optimized in 3.7+;
# We need list_if37 and compare_chained37.

View File

@@ -641,6 +641,9 @@ class Python37Parser(Python37BaseParser):
expr ::= if_exp_37b
if_exp_37a ::= and_not expr JUMP_FORWARD come_froms expr COME_FROM
if_exp_37b ::= expr jmp_false expr POP_JUMP_IF_FALSE jump_forward_else expr
or ::= expr jmp_true expr
jmp_false_cf ::= POP_JUMP_IF_FALSE COME_FROM
comp_if ::= or jmp_false_cf comp_iter
"""
def p_comprehension3(self, args):