mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
PEP 308 implementation, including minor refdocs and some testcases. It
breaks the parser module, because it adds the if/else construct as well as
two new grammar rules for backward compatibility. If no one else fixes
parsermodule, I guess I'll go ahead and fix it later this week.
The TeX code was checked with texcheck.py, but not rendered. There is
actually a slight incompatibility:
>>> (x for x in lambda:0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: iteration over non-sequence
changes into
>>> (x for x in lambda: 0)
File "<stdin>", line 1
(x for x in lambda: 0)
^
SyntaxError: invalid syntax
Since there's no way the former version can be useful, it's probably a
bugfix ;)
This commit is contained in:
parent
d3a5f53a27
commit
dca3b9c797
11 changed files with 878 additions and 642 deletions
|
|
@ -798,3 +798,28 @@ verify(len(list(g)) == 10)
|
|||
x = 10; t = False; g = ((i,j) for i in range(x) if t for j in range(x))
|
||||
x = 5; t = True;
|
||||
verify([(i,j) for i in range(10) for j in range(5)] == list(g))
|
||||
|
||||
# Test ifelse expressions in various cases
|
||||
def _checkeval(msg, ret):
|
||||
"helper to check that evaluation of expressions is done correctly"
|
||||
print x
|
||||
return ret
|
||||
|
||||
verify([ x() for x in lambda: True, lambda: False if x() ] == [True])
|
||||
verify([ x() for x in (lambda: True, lambda: False) if x() ] == [True])
|
||||
verify([ x(False) for x in (lambda x: False if x else True, lambda x: True if x else False) if x(False) ] == [True])
|
||||
verify((5 if 1 else _checkeval("check 1", 0)) == 5)
|
||||
verify((_checkeval("check 2", 0) if 0 else 5) == 5)
|
||||
verify((5 and 6 if 0 else 1) == 1)
|
||||
verify(((5 and 6) if 0 else 1) == 1)
|
||||
verify((5 and (6 if 1 else 1)) == 6)
|
||||
verify((0 or _checkeval("check 3", 2) if 0 else 3) == 3)
|
||||
verify((1 or _checkeval("check 4", 2) if 1 else _checkeval("check 5", 3)) == 1)
|
||||
verify((0 or 5 if 1 else _checkeval("check 6", 3)) == 5)
|
||||
verify((not 5 if 1 else 1) == False)
|
||||
verify((not 5 if 0 else 1) == 1)
|
||||
verify((6 + 1 if 1 else 2) == 7)
|
||||
verify((6 - 1 if 1 else 2) == 5)
|
||||
verify((6 * 2 if 1 else 4) == 12)
|
||||
verify((6 / 2 if 1 else 3) == 3)
|
||||
verify((6 < 4 if 0 else 2) == 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue