diff options
author | Raymond Hettinger <python@rcn.com> | 2009-03-10 12:56:32 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-03-10 12:56:32 (GMT) |
commit | 5bb0f0e072ef22fa16bf281bc5e6b5d7a1594beb (patch) | |
tree | 1621e012d8d1ad69a2afe5f9bc17cdbb815466f4 /Modules/_collectionsmodule.c | |
parent | 060c7f6bbafdaeb4b73ce34f1bb34e4ac76f2d92 (diff) | |
download | cpython-5bb0f0e072ef22fa16bf281bc5e6b5d7a1594beb.zip cpython-5bb0f0e072ef22fa16bf281bc5e6b5d7a1594beb.tar.gz cpython-5bb0f0e072ef22fa16bf281bc5e6b5d7a1594beb.tar.bz2 |
For collections.deque() objects, expose the maxlen parameter as a read-only attribute.
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r-- | Modules/_collectionsmodule.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 8d27b88..f8d656c 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -812,6 +812,20 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs) return 0; } +static PyObject * +deque_get_maxlen(dequeobject *deque) +{ + if (deque->maxlen == -1) + Py_RETURN_NONE; + return PyLong_FromSsize_t(deque->maxlen); +} + +static PyGetSetDef deque_getset[] = { + {"maxlen", (getter)deque_get_maxlen, (setter)NULL, + "maximum size of a deque or None if unbounded"}, + {0} +}; + static PySequenceMethods deque_as_sequence = { (lenfunc)deque_len, /* sq_length */ 0, /* sq_concat */ @@ -893,7 +907,7 @@ static PyTypeObject deque_type = { 0, /* tp_iternext */ deque_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + deque_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ |