MCPcopy Index your code
hub / github.com/python/cpython / testLambdas

Method testLambdas

Lib/test/test_scope.py:281–303  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

279 """)
280
281 def testLambdas(self):
282
283 f1 = lambda x: lambda y: x + y
284 inc = f1(1)
285 plus10 = f1(10)
286 self.assertEqual(inc(1), 2)
287 self.assertEqual(plus10(5), 15)
288
289 f2 = lambda x: (lambda : lambda y: x + y)()
290 inc = f2(1)
291 plus10 = f2(10)
292 self.assertEqual(inc(1), 2)
293 self.assertEqual(plus10(5), 15)
294
295 f3 = lambda x: lambda y: global_x + y
296 global_x = 1
297 inc = f3(None)
298 self.assertEqual(inc(2), 3)
299
300 f8 = lambda x, y, z: lambda a, b, c: lambda : z * (b + y)
301 g = f8(1, 2, 3)
302 h = g(2, 4, 6)
303 self.assertEqual(h(), 18)
304
305 def testUnboundLocal(self):
306

Callers

nothing calls this directly

Calls 6

f1Function · 0.85
f2Function · 0.85
f8Function · 0.85
gFunction · 0.70
hClass · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected