Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
56411aac
Kaydet (Commit)
56411aac
authored
Mar 10, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
For collections.deque() objects, expose the maxlen parameter as a read-only attribute.
üst
bac769bb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
1 deletion
+36
-1
collections.rst
Doc/library/collections.rst
+9
-0
test_deque.py
Lib/test/test_deque.py
+10
-0
NEWS
Misc/NEWS
+2
-0
_collectionsmodule.c
Modules/_collectionsmodule.c
+15
-1
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
56411aac
...
...
@@ -382,6 +382,15 @@ counts, but the output will exclude results with counts of zero or less.
``d.appendleft(d.pop())``.
Deque objects also provide one read-only attribute:
.. attribute:: maxlen
Maximum size of a deque or *None* if unbounded.
.. versionadded:: 2.7
In addition to the above, deques support iteration, pickling, ``len(d)``,
``reversed(d)``, ``copy.copy(d)``, ``copy.deepcopy(d)``, membership testing with
the :keyword:`in` operator, and subscript references such as ``d[-1]``. Indexed
...
...
Lib/test/test_deque.py
Dosyayı görüntüle @
56411aac
...
...
@@ -104,6 +104,16 @@ class TestBasic(unittest.TestCase):
d
.
extendleft
(
it
)
self
.
assertEqual
(
list
(
it
),
[])
def
test_maxlen_attribute
(
self
):
self
.
assertEqual
(
deque
()
.
maxlen
,
None
)
self
.
assertEqual
(
deque
(
'abc'
)
.
maxlen
,
None
)
self
.
assertEqual
(
deque
(
'abc'
,
maxlen
=
4
)
.
maxlen
,
4
)
self
.
assertEqual
(
deque
(
'abc'
,
maxlen
=
2
)
.
maxlen
,
2
)
self
.
assertEqual
(
deque
(
'abc'
,
maxlen
=
0
)
.
maxlen
,
0
)
with
self
.
assertRaises
(
AttributeError
):
d
=
deque
(
'abc'
)
d
.
maxlen
=
10
def
test_comparisons
(
self
):
d
=
deque
(
'xabc'
);
d
.
popleft
()
for
e
in
[
d
,
deque
(
'abc'
),
deque
(
'ab'
),
deque
(),
list
(
d
)]:
...
...
Misc/NEWS
Dosyayı görüntüle @
56411aac
...
...
@@ -168,6 +168,8 @@ Core and Builtins
Library
-------
- collections.deque() objects now have a read-only attribute called maxlen.
- Issue #2638: Show a window constructed with tkSimpleDialog.Dialog only after
it is has been populated and properly configured in order to prevent
window flashing.
...
...
Modules/_collectionsmodule.c
Dosyayı görüntüle @
56411aac
...
...
@@ -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 */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment