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

Method testNonLocalFunction

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

Source from the content-addressed store, hash-verified

656 nestedcell_get()
657
658 def testNonLocalFunction(self):
659
660 def f(x):
661 def inc():
662 nonlocal x
663 x += 1
664 return x
665 def dec():
666 nonlocal x
667 x -= 1
668 return x
669 return inc, dec
670
671 inc, dec = f(0)
672 self.assertEqual(inc(), 1)
673 self.assertEqual(inc(), 2)
674 self.assertEqual(dec(), 1)
675 self.assertEqual(dec(), 0)
676
677 def testNonLocalMethod(self):
678 def f(x):

Callers

nothing calls this directly

Calls 3

fFunction · 0.70
decFunction · 0.50
assertEqualMethod · 0.45

Tested by

no test coverage detected