Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 619eea6

Browse files
committed
PEP 227 implementation
test_new: new.code() noew takes two more arguments test_grammer: Add a bunch of test cases for lambda (not really PEP 227 related)
1 parent 4588c78 commit 619eea6

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lib/test/output/test_grammar

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ file_input
1313
expr_input
1414
eval_input
1515
funcdef
16+
lambdef
17+
SyntaxError expected for "lambda x: x = 2"
1618
simple_stmt
1719
expr_stmt
1820
print_stmt

Lib/test/test_grammar.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,20 @@ def d22v(a, b, c=1, d=2, *rest): pass
246246
d22v(1, 2, *(3, 4, 5))
247247
d22v(1, *(2, 3), **{'d': 4})
248248

249+
### lambdef: 'lambda' [varargslist] ':' test
250+
print 'lambdef'
251+
l1 = lambda : 0
252+
verify(l1() == 0)
253+
l2 = lambda : a[d] # XXX just testing the expression
254+
l3 = lambda : [2 < x for x in [-1, 3, 0L]]
255+
verify(l3() == [0, 1, 0])
256+
l4 = lambda x = lambda y = lambda z=1 : z : y() : x()
257+
verify(l4() == 1)
258+
l5 = lambda x, y, z=2: x + y + z
259+
verify(l5(1, 2) == 5)
260+
verify(l5(1, 2, 3) == 6)
261+
check_syntax("lambda x: x = 2")
262+
249263
### stmt: simple_stmt | compound_stmt
250264
# Tested below
251265

Lib/test/test_new.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def break_yolks(self):
5858

5959
# bogus test of new.code()
6060
print 'new.code()'
61-
d = new.code(3, 3, 3, 3, codestr, (), (), (), "<string>", "<name>", 1, "")
61+
d = new.code(3, 3, 3, 3, codestr, (), (), (), (), (),
62+
"<string>", "<name>", 1, "")
6263
if verbose:
6364
print d

0 commit comments

Comments
 (0)