diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-07-29 23:19:43 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-07-29 23:19:43 (GMT) |
commit | c4607aeedd19fad5e5fe1a6a72a0c79d014ee4e1 (patch) | |
tree | 7b854ccc3b42a80fdb62f6a3fa82ece2a394c281 /Objects | |
parent | 4f921c2e061507f6d93002c454e063db2acaf7ea (diff) | |
download | cpython-c4607aeedd19fad5e5fe1a6a72a0c79d014ee4e1.zip cpython-c4607aeedd19fad5e5fe1a6a72a0c79d014ee4e1.tar.gz cpython-c4607aeedd19fad5e5fe1a6a72a0c79d014ee4e1.tar.bz2 |
make the types of None and Ellipsis callable
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 34 | ||||
-rw-r--r-- | Objects/sliceobject.c | 29 |
2 files changed, 63 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c index 27d7089..f2f4363 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1277,6 +1277,16 @@ none_dealloc(PyObject* ignore) Py_FatalError("deallocating None"); } +static PyObject * +none_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + if (PyTuple_GET_SIZE(args) || (kwargs && PyDict_Size(kwargs))) { + PyErr_SetString(PyExc_TypeError, "NoneType takes no arguments"); + return NULL; + } + Py_RETURN_NONE; +} + static int none_bool(PyObject *v) { @@ -1335,6 +1345,30 @@ static PyTypeObject PyNone_Type = { 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ + 0, /*tp_call */ + 0, /*tp_str */ + 0, /*tp_getattro */ + 0, /*tp_setattro */ + 0, /*tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /*tp_flags */ + 0, /*tp_doc */ + 0, /*tp_traverse */ + 0, /*tp_clear */ + 0, /*tp_richcompare */ + 0, /*tp_weaklistoffset */ + 0, /*tp_iter */ + 0, /*tp_iternext */ + 0, /*tp_methods */ + 0, /*tp_members */ + 0, /*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 */ + none_new, /*tp_new */ }; PyObject _Py_NoneStruct = { diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 51c53a8..53cc951 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -17,6 +17,17 @@ this type and there is exactly one in existence. #include "structmember.h" static PyObject * +ellipsis_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + if (PyTuple_GET_SIZE(args) || (kwargs && PyDict_Size(kwargs))) { + PyErr_SetString(PyExc_TypeError, "EllipsisType takes no arguments"); + return NULL; + } + Py_INCREF(Py_Ellipsis); + return Py_Ellipsis; +} + +static PyObject * ellipsis_repr(PyObject *op) { return PyUnicode_FromString("Ellipsis"); @@ -43,6 +54,24 @@ PyTypeObject PyEllipsis_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* 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 */ + ellipsis_new, /* tp_new */ }; PyObject _Py_EllipsisObject = { |