attribute of an empty cell object. Now a ValueError is raised.
Backport of r59170.
verify(c[0].__class__.__name__ == "cell") # don't have a type object handy
cantset(f, "func_closure", c)
+def test_empty_cell():
+ def f(): print a
+ try:
+ f.func_closure[0].cell_contents
+ except ValueError:
+ pass
+ else:
+ raise TestFailed, "shouldn't be able to read an empty cell"
+
+ a = 12
+
def test_func_doc():
def f(): pass
verify(f.__doc__ is None)
def testmore():
test_func_closure()
+ test_empty_cell()
test_func_doc()
test_func_globals()
test_func_name()
-+++++++++++
++++++++++++
Python News
+++++++++++
Core and builtins
-----------------
+- Issue #1445: Fix a SystemError when accessing the ``cell_contents``
+ attribute of an empty cell object.
+
- Issue #1265: Fix a problem with sys.settrace, if the tracing function uses a
generator expression when at the same time the executed code is closing a
paused generator.
static PyObject *
cell_get_contents(PyCellObject *op, void *closure)
{
- Py_XINCREF(op->ob_ref);
+ if (op->ob_ref == NULL)
+ {
+ PyErr_SetString(PyExc_ValueError, "Cell is empty");
+ return NULL;
+ }
+ Py_INCREF(op->ob_ref);
return op->ob_ref;
}