]> granicus.if.org Git - python/commitdiff
PEP 227 implementation
authorJeremy Hylton <jeremy@alum.mit.edu>
Thu, 25 Jan 2001 20:12:27 +0000 (20:12 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Thu, 25 Jan 2001 20:12:27 +0000 (20:12 +0000)
test_new: new.code() noew takes two more arguments
test_grammer: Add a bunch of test cases for lambda (not really PEP 227 related)

Lib/test/output/test_grammar
Lib/test/test_grammar.py
Lib/test/test_new.py

index bc9c9d49aaa1c8d489dc2c652f88adbaf6f3dc2e..b75c22f3d5b4da93c31ce024763a31796ba1692d 100644 (file)
@@ -13,6 +13,8 @@ file_input
 expr_input
 eval_input
 funcdef
+lambdef
+SyntaxError expected for "lambda x: x = 2"
 simple_stmt
 expr_stmt
 print_stmt
index a8d26dcdcc4daf3ab21368bf202e5cc98e98eb3f..8030e691e19f63cd39cf2784016718371bd16287 100644 (file)
@@ -246,6 +246,20 @@ d22v(*(1, 2, 3, 4))
 d22v(1, 2, *(3, 4, 5))
 d22v(1, *(2, 3), **{'d': 4})
 
+### lambdef: 'lambda' [varargslist] ':' test
+print 'lambdef'
+l1 = lambda : 0
+verify(l1() == 0)
+l2 = lambda : a[d] # XXX just testing the expression
+l3 = lambda : [2 < x for x in [-1, 3, 0L]]
+verify(l3() == [0, 1, 0])
+l4 = lambda x = lambda y = lambda z=1 : z : y() : x()
+verify(l4() == 1)
+l5 = lambda x, y, z=2: x + y + z
+verify(l5(1, 2) == 5)
+verify(l5(1, 2, 3) == 6)
+check_syntax("lambda x: x = 2")
+
 ### stmt: simple_stmt | compound_stmt
 # Tested below
 
index 70ea38bea5ea87dc7ac0202413cf8232a48650e6..af26f01e6fca1a6054b5256dd1fa6bcfcbb6d987 100644 (file)
@@ -58,6 +58,7 @@ if g['c'] != 3:
 
 # bogus test of new.code()
 print 'new.code()'
-d = new.code(3, 3, 3, 3, codestr, (), (), (), "<string>", "<name>", 1, "")
+d = new.code(3, 3, 3, 3, codestr, (), (), (), (), (),
+             "<string>", "<name>", 1, "")
 if verbose:
     print d