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
68995867
Kaydet (Commit)
68995867
authored
Eki 10, 2007
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Accept Jim Jewett's api suggestion to use None instead of -1 to indicate unbounded deques.
üst
77ae87c1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
12 deletions
+45
-12
collections.rst
Doc/library/collections.rst
+1
-1
test_deque.py
Lib/test/test_deque.py
+18
-1
_collectionsmodule.c
Modules/_collectionsmodule.c
+26
-10
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
68995867
...
...
@@ -51,7 +51,7 @@ ordered dictionaries.
.. versionadded:: 2.4
If *maxlen* is not specified or is *
-1
*, deques may grow to an
If *maxlen* is not specified or is *
None
*, deques may grow to an
arbitrary length. Otherwise, the deque is bounded to the specified maximum
length. Once a bounded length deque is full, when new items are added, a
corresponding number of items are discarded from the opposite end. Bounded
...
...
Lib/test/test_deque.py
Dosyayı görüntüle @
68995867
...
...
@@ -48,6 +48,7 @@ class TestBasic(unittest.TestCase):
self
.
assertEqual
(
list
(
d
),
range
(
50
,
150
))
def
test_maxlen
(
self
):
self
.
assertRaises
(
ValueError
,
deque
,
'abc'
,
-
1
)
self
.
assertRaises
(
ValueError
,
deque
,
'abc'
,
-
2
)
d
=
deque
(
range
(
10
),
maxlen
=
3
)
self
.
assertEqual
(
repr
(
d
),
'deque([7, 8, 9], maxlen=3)'
)
...
...
@@ -73,7 +74,7 @@ class TestBasic(unittest.TestCase):
fo
.
close
()
os
.
remove
(
test_support
.
TESTFN
)
d
=
deque
(
range
(
10
),
maxlen
=
-
1
)
d
=
deque
(
range
(
10
),
maxlen
=
None
)
self
.
assertEqual
(
repr
(
d
),
'deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])'
)
try
:
fo
=
open
(
test_support
.
TESTFN
,
"wb"
)
...
...
@@ -489,6 +490,22 @@ class TestSubclass(unittest.TestCase):
self
.
assertEqual
(
type
(
d
),
type
(
e
))
self
.
assertEqual
(
list
(
d
),
list
(
e
))
d
=
Deque
(
'abcde'
,
maxlen
=
4
)
e
=
d
.
__copy__
()
self
.
assertEqual
(
type
(
d
),
type
(
e
))
self
.
assertEqual
(
list
(
d
),
list
(
e
))
e
=
Deque
(
d
)
self
.
assertEqual
(
type
(
d
),
type
(
e
))
self
.
assertEqual
(
list
(
d
),
list
(
e
))
s
=
pickle
.
dumps
(
d
)
e
=
pickle
.
loads
(
s
)
self
.
assertNotEqual
(
id
(
d
),
id
(
e
))
self
.
assertEqual
(
type
(
d
),
type
(
e
))
self
.
assertEqual
(
list
(
d
),
list
(
e
))
## def test_pickle(self):
## d = Deque('abc')
## d.append(d)
...
...
Modules/_collectionsmodule.c
Dosyayı görüntüle @
68995867
...
...
@@ -598,8 +598,11 @@ deque_nohash(PyObject *self)
static
PyObject
*
deque_copy
(
PyObject
*
deque
)
{
return
PyObject_CallFunction
((
PyObject
*
)(
Py_Type
(
deque
)),
"Oi"
,
deque
,
((
dequeobject
*
)
deque
)
->
maxlen
,
NULL
);
if
(((
dequeobject
*
)
deque
)
->
maxlen
==
-
1
)
return
PyObject_CallFunction
((
PyObject
*
)(
Py_Type
(
deque
)),
"O"
,
deque
,
NULL
);
else
return
PyObject_CallFunction
((
PyObject
*
)(
Py_Type
(
deque
)),
"Oi"
,
deque
,
((
dequeobject
*
)
deque
)
->
maxlen
,
NULL
);
}
PyDoc_STRVAR
(
copy_doc
,
"Return a shallow copy of a deque."
);
...
...
@@ -617,10 +620,17 @@ deque_reduce(dequeobject *deque)
Py_XDECREF
(
dict
);
return
NULL
;
}
if
(
dict
==
NULL
)
result
=
Py_BuildValue
(
"O(Oi)"
,
Py_Type
(
deque
),
aslist
,
deque
->
maxlen
);
else
result
=
Py_BuildValue
(
"O(Oi)O"
,
Py_Type
(
deque
),
aslist
,
deque
->
maxlen
,
dict
);
if
(
dict
==
NULL
)
{
if
(
deque
->
maxlen
==
-
1
)
result
=
Py_BuildValue
(
"O(O)"
,
Py_Type
(
deque
),
aslist
);
else
result
=
Py_BuildValue
(
"O(Oi)"
,
Py_Type
(
deque
),
aslist
,
deque
->
maxlen
);
}
else
{
if
(
deque
->
maxlen
==
-
1
)
result
=
Py_BuildValue
(
"O(OO)O"
,
Py_Type
(
deque
),
aslist
,
Py_None
,
dict
);
else
result
=
Py_BuildValue
(
"O(Oi)O"
,
Py_Type
(
deque
),
aslist
,
deque
->
maxlen
,
dict
);
}
Py_XDECREF
(
dict
);
Py_DECREF
(
aslist
);
return
result
;
...
...
@@ -797,14 +807,20 @@ static int
deque_init
(
dequeobject
*
deque
,
PyObject
*
args
,
PyObject
*
kwdargs
)
{
PyObject
*
iterable
=
NULL
;
PyObject
*
maxlenobj
=
NULL
;
int
maxlen
=
-
1
;
char
*
kwlist
[]
=
{
"iterable"
,
"maxlen"
,
0
};
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwdargs
,
"|Oi:deque"
,
kwlist
,
&
iterable
,
&
maxlen
))
return
-
1
;
if
(
maxlen
<
-
1
)
{
PyErr_SetString
(
PyExc_ValueError
,
"maxlen must be -1 or greater"
);
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwdargs
,
"|OO:deque"
,
kwlist
,
&
iterable
,
&
maxlenobj
))
return
-
1
;
if
(
maxlenobj
!=
NULL
&&
maxlenobj
!=
Py_None
)
{
maxlen
=
PyInt_AsLong
(
maxlenobj
);
if
(
maxlen
==
-
1
&&
PyErr_Occurred
())
return
-
1
;
if
(
maxlen
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"maxlen must be non-negative"
);
return
-
1
;
}
}
deque
->
maxlen
=
maxlen
;
if
(
iterable
!=
NULL
)
{
...
...
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