diff options
author | Raymond Hettinger <python@rcn.com> | 2009-03-10 12:50:59 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-03-10 12:50:59 (GMT) |
commit | 56411aac79ee3c55ce11cea55ec7921f5d96654a (patch) | |
tree | fe5e9cb2f5198b71e991f64a13345cb0952dc2a8 /Modules | |
parent | bac769bb5e7656c65e75e27c9d4c914b5d98f12c (diff) | |
download | cpython-56411aac79ee3c55ce11cea55ec7921f5d96654a.zip cpython-56411aac79ee3c55ce11cea55ec7921f5d96654a.tar.gz cpython-56411aac79ee3c55ce11cea55ec7921f5d96654a.tar.bz2 |
For collections.deque() objects, expose the maxlen parameter as a read-only attribute.
Diffstat (limited to 'Modules')
-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 9532f1b..a4fdf76 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -870,6 +870,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 PyInt_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 */ @@ -951,7 +965,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 */ |