mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-30486: Allow setting cell value (#1840)
The cell_contents attribute of the cell object is now writable.
This commit is contained in:
parent
6cca5c8459
commit
64505a1f6c
4 changed files with 41 additions and 4 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue