bpo-35911: add cell constructor (GH-11771)

Add a cell constructor, expose the cell type in the types module.
This commit is contained in:
Pierre Glaser 2019-02-07 20:36:48 +01:00 committed by Antoine Pitrou
parent f289084c83
commit df8d2cde63
6 changed files with 71 additions and 2 deletions

View file

@ -83,6 +83,15 @@ class FunctionPropertiesTest(FuncAttrsTest):
self.assertEqual(c[0].__class__.__name__, "cell")
self.cannot_set_attr(f, "__closure__", c, AttributeError)
def test_cell_new(self):
cell_obj = types.CellType(1)
self.assertEqual(cell_obj.cell_contents, 1)
cell_obj = types.CellType()
msg = "shouldn't be able to read an empty cell"
with self.assertRaises(ValueError, msg=msg):
cell_obj.cell_contents
def test_empty_cell(self):
def f(): print(a)
try: