diff options
author | Lisa Roach <lisaroach14@gmail.com> | 2017-06-08 11:43:26 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-06-08 11:43:26 (GMT) |
commit | 64505a1f6c0af4574e17e823b27ffe24eca44df5 (patch) | |
tree | d2b40e19b44e4ab50f92440a54facc59038da4b3 /Lib | |
parent | 6cca5c8459cc439cb050010ffa762a03859d3051 (diff) | |
download | cpython-64505a1f6c0af4574e17e823b27ffe24eca44df5.zip cpython-64505a1f6c0af4574e17e823b27ffe24eca44df5.tar.gz cpython-64505a1f6c0af4574e17e823b27ffe24eca44df5.tar.bz2 |
bpo-30486: Allow setting cell value (#1840)
The cell_contents attribute of the cell object is now writable.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_funcattrs.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py index 8f481bb..35fd657 100644 --- a/Lib/test/test_funcattrs.py +++ b/Lib/test/test_funcattrs.py @@ -93,6 +93,26 @@ class FunctionPropertiesTest(FuncAttrsTest): self.fail("shouldn't be able to read an empty cell") a = 12 + def test_set_cell(self): + a = 12 + def f(): return a + c = f.__closure__ + c[0].cell_contents = 9 + self.assertEqual(c[0].cell_contents, 9) + self.assertEqual(f(), 9) + self.assertEqual(a, 9) + del c[0].cell_contents + try: + c[0].cell_contents + except ValueError: + pass + else: + self.fail("shouldn't be able to read an empty cell") + with self.assertRaises(NameError): + f() + with self.assertRaises(UnboundLocalError): + print(a) + def test___name__(self): self.assertEqual(self.b.__name__, 'b') self.b.__name__ = 'c' |