bpo-30486: Allow setting cell value (#1840)

The cell_contents attribute of the cell object is now writable.
This commit is contained in:
Lisa Roach 2017-06-08 04:43:26 -07:00 committed by Serhiy Storchaka
parent 6cca5c8459
commit 64505a1f6c
4 changed files with 41 additions and 4 deletions

View file

@ -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'