summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorPierre Glaser <pierreglaser@msn.com>2019-02-07 19:36:48 (GMT)
committerAntoine Pitrou <pitrou@free.fr>2019-02-07 19:36:48 (GMT)
commitdf8d2cde63c865446468351f8f648e1c7bd45109 (patch)
tree1cc555d57319990602a4987cbf21ee225c4ff2a1 /Objects
parentf289084c83190cc72db4a70c58f007ec62e75247 (diff)
downloadcpython-df8d2cde63c865446468351f8f648e1c7bd45109.zip
cpython-df8d2cde63c865446468351f8f648e1c7bd45109.tar.gz
cpython-df8d2cde63c865446468351f8f648e1c7bd45109.tar.bz2
bpo-35911: add cell constructor (GH-11771)
Add a cell constructor, expose the cell type in the types module.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/cellobject.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/Objects/cellobject.c b/Objects/cellobject.c
index 86bebb9..4e359f8 100644
--- a/Objects/cellobject.c
+++ b/Objects/cellobject.c
@@ -20,6 +20,37 @@ PyCell_New(PyObject *obj)
return (PyObject *)op;
}
+PyDoc_STRVAR(cell_new_doc,
+"cell([contents])\n"
+"--\n"
+"\n"
+"Create a new cell object.\n"
+"\n"
+" contents\n"
+" the contents of the cell. If not specified, the cell will be empty,\n"
+" and \n further attempts to access its cell_contents attribute will\n"
+" raise a ValueError.");
+
+
+static PyObject *
+cell_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *obj = NULL;
+
+ if (!_PyArg_NoKeywords("cell", kwargs)) {
+ goto exit;
+ }
+ /* min = 0: we allow the cell to be empty */
+ if (!PyArg_UnpackTuple(args, "cell", 0, 1, &obj)) {
+ goto exit;
+ }
+ return_value = PyCell_New(obj);
+
+exit:
+ return return_value;
+}
+
PyObject *
PyCell_Get(PyObject *op)
{
@@ -146,7 +177,7 @@ PyTypeObject PyCell_Type = {
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
- 0, /* tp_doc */
+ cell_new_doc, /* tp_doc */
(traverseproc)cell_traverse, /* tp_traverse */
(inquiry)cell_clear, /* tp_clear */
cell_richcompare, /* tp_richcompare */
@@ -156,4 +187,13 @@ PyTypeObject PyCell_Type = {
0, /* tp_methods */
0, /* tp_members */
cell_getsetlist, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)cell_new, /* tp_new */
+ 0, /* tp_free */
};