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
cbbaa960
Kaydet (Commit)
cbbaa960
authored
Şub 25, 2011
tarafından
Eli Bendersky
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #10516: adding list.clear() and list.copy() methods
üst
3108f983
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
2 deletions
+81
-2
stdtypes.rst
Doc/library/stdtypes.rst
+13
-1
__init__.py
Lib/collections/__init__.py
+2
-0
list_tests.py
Lib/test/list_tests.py
+42
-0
test_descrtut.py
Lib/test/test_descrtut.py
+2
-0
NEWS
Misc/NEWS
+2
-0
listobject.c
Objects/listobject.c
+20
-1
No files found.
Doc/library/stdtypes.rst
Dosyayı görüntüle @
cbbaa960
...
@@ -1642,6 +1642,8 @@ Note that while lists allow their items to be of any type, bytearray object
...
@@ -1642,6 +1642,8 @@ Note that while lists allow their items to be of any type, bytearray object
single: append() (sequence method)
single: append() (sequence method)
single: extend() (sequence method)
single: extend() (sequence method)
single: count() (sequence method)
single: count() (sequence method)
single: clear() (sequence method)
single: copy() (sequence method)
single: index() (sequence method)
single: index() (sequence method)
single: insert() (sequence method)
single: insert() (sequence method)
single: pop() (sequence method)
single: pop() (sequence method)
...
@@ -1673,6 +1675,12 @@ Note that while lists allow their items to be of any type, bytearray object
...
@@ -1673,6 +1675,12 @@ Note that while lists allow their items to be of any type, bytearray object
| ``s.extend(x)`` | same as ``s[len(s):len(s)] = | \(2) |
| ``s.extend(x)`` | same as ``s[len(s):len(s)] = | \(2) |
| | x`` | |
| | x`` | |
+------------------------------+--------------------------------+---------------------+
+------------------------------+--------------------------------+---------------------+
| ``s.clear()`` | remove all items from ``s`` | \(8) |
| | | |
+------------------------------+--------------------------------+---------------------+
| ``s.copy()`` | return a shallow copy of ``s`` | \(8) |
| | | |
+------------------------------+--------------------------------+---------------------+
| ``s.count(x)`` | return number of *i*'s for | |
| ``s.count(x)`` | return number of *i*'s for | |
| | which ``s[i] == x`` | |
| | which ``s[i] == x`` | |
+------------------------------+--------------------------------+---------------------+
+------------------------------+--------------------------------+---------------------+
...
@@ -1749,7 +1757,11 @@ Notes:
...
@@ -1749,7 +1757,11 @@ Notes:
detect that the list has been mutated during a sort.
detect that the list has been mutated during a sort.
(8)
(8)
:meth:`sort` is not supported by :class:`bytearray` objects.
:meth:`clear`, :meth:`!copy` and :meth:`sort` are not supported by
:class:`bytearray` objects.
.. versionadded:: 3.3
:meth:`clear` and :meth:`!copy` methods.
.. _bytes-methods:
.. _bytes-methods:
...
...
Lib/collections/__init__.py
Dosyayı görüntüle @
cbbaa960
...
@@ -844,6 +844,8 @@ class UserList(MutableSequence):
...
@@ -844,6 +844,8 @@ class UserList(MutableSequence):
def
insert
(
self
,
i
,
item
):
self
.
data
.
insert
(
i
,
item
)
def
insert
(
self
,
i
,
item
):
self
.
data
.
insert
(
i
,
item
)
def
pop
(
self
,
i
=-
1
):
return
self
.
data
.
pop
(
i
)
def
pop
(
self
,
i
=-
1
):
return
self
.
data
.
pop
(
i
)
def
remove
(
self
,
item
):
self
.
data
.
remove
(
item
)
def
remove
(
self
,
item
):
self
.
data
.
remove
(
item
)
def
clear
(
self
):
self
.
data
.
clear
()
def
copy
(
self
):
return
self
.
data
.
copy
()
def
count
(
self
,
item
):
return
self
.
data
.
count
(
item
)
def
count
(
self
,
item
):
return
self
.
data
.
count
(
item
)
def
index
(
self
,
item
,
*
args
):
return
self
.
data
.
index
(
item
,
*
args
)
def
index
(
self
,
item
,
*
args
):
return
self
.
data
.
index
(
item
,
*
args
)
def
reverse
(
self
):
self
.
data
.
reverse
()
def
reverse
(
self
):
self
.
data
.
reverse
()
...
...
Lib/test/list_tests.py
Dosyayı görüntüle @
cbbaa960
...
@@ -425,6 +425,48 @@ class CommonTest(seq_tests.CommonTest):
...
@@ -425,6 +425,48 @@ class CommonTest(seq_tests.CommonTest):
self
.
assertRaises
(
TypeError
,
u
.
reverse
,
42
)
self
.
assertRaises
(
TypeError
,
u
.
reverse
,
42
)
def
test_clear
(
self
):
u
=
self
.
type2test
([
2
,
3
,
4
])
u
.
clear
()
self
.
assertEqual
(
u
,
[])
u
=
self
.
type2test
([])
u
.
clear
()
self
.
assertEqual
(
u
,
[])
u
=
self
.
type2test
([])
u
.
append
(
1
)
u
.
clear
()
u
.
append
(
2
)
self
.
assertEqual
(
u
,
[
2
])
self
.
assertRaises
(
TypeError
,
u
.
clear
,
None
)
def
test_copy
(
self
):
u
=
self
.
type2test
([
1
,
2
,
3
])
v
=
u
.
copy
()
self
.
assertEqual
(
v
,
[
1
,
2
,
3
])
u
=
self
.
type2test
([])
v
=
u
.
copy
()
self
.
assertEqual
(
v
,
[])
# test that it's indeed a copy and not a reference
u
=
self
.
type2test
([
'a'
,
'b'
])
v
=
u
.
copy
()
v
.
append
(
'i'
)
self
.
assertEqual
(
u
,
[
'a'
,
'b'
])
self
.
assertEqual
(
v
,
u
+
[
'i'
])
# test that it's a shallow, not a deep copy
u
=
self
.
type2test
([
1
,
2
,
[
3
,
4
],
5
])
v
=
u
.
copy
()
v
[
2
]
.
append
(
666
)
self
.
assertEqual
(
u
,
[
1
,
2
,
[
3
,
4
,
666
],
5
])
self
.
assertEqual
(
u
,
v
)
self
.
assertRaises
(
TypeError
,
u
.
copy
,
None
)
def
test_sort
(
self
):
def
test_sort
(
self
):
u
=
self
.
type2test
([
1
,
0
])
u
=
self
.
type2test
([
1
,
0
])
u
.
sort
()
u
.
sort
()
...
...
Lib/test/test_descrtut.py
Dosyayı görüntüle @
cbbaa960
...
@@ -199,6 +199,8 @@ You can get the information from the list type:
...
@@ -199,6 +199,8 @@ You can get the information from the list type:
'__str__',
'__str__',
'__subclasshook__',
'__subclasshook__',
'append',
'append',
'clear',
'copy',
'count',
'count',
'extend',
'extend',
'index',
'index',
...
...
Misc/NEWS
Dosyayı görüntüle @
cbbaa960
...
@@ -30,6 +30,8 @@ Core and Builtins
...
@@ -30,6 +30,8 @@ Core and Builtins
- Check for NULL result in PyType_FromSpec.
- Check for NULL result in PyType_FromSpec.
- Issue #10516: New copy() and clear() methods for lists.
Library
Library
-------
-------
...
...
Objects/listobject.c
Dosyayı görüntüle @
cbbaa960
...
@@ -746,6 +746,19 @@ listinsert(PyListObject *self, PyObject *args)
...
@@ -746,6 +746,19 @@ listinsert(PyListObject *self, PyObject *args)
return
NULL
;
return
NULL
;
}
}
static
PyObject
*
listclear
(
PyListObject
*
self
)
{
list_clear
(
self
);
Py_RETURN_NONE
;
}
static
PyObject
*
listcopy
(
PyListObject
*
self
)
{
return
list_slice
(
self
,
0
,
Py_SIZE
(
self
));
}
static
PyObject
*
static
PyObject
*
listappend
(
PyListObject
*
self
,
PyObject
*
v
)
listappend
(
PyListObject
*
self
,
PyObject
*
v
)
{
{
...
@@ -2322,6 +2335,10 @@ PyDoc_STRVAR(reversed_doc,
...
@@ -2322,6 +2335,10 @@ PyDoc_STRVAR(reversed_doc,
"L.__reversed__() -- return a reverse iterator over the list"
);
"L.__reversed__() -- return a reverse iterator over the list"
);
PyDoc_STRVAR
(
sizeof_doc
,
PyDoc_STRVAR
(
sizeof_doc
,
"L.__sizeof__() -- size of L in memory, in bytes"
);
"L.__sizeof__() -- size of L in memory, in bytes"
);
PyDoc_STRVAR
(
clear_doc
,
"L.clear() -> None -- remove all items from L"
);
PyDoc_STRVAR
(
copy_doc
,
"L.copy() -> list -- a shallow copy of L"
);
PyDoc_STRVAR
(
append_doc
,
PyDoc_STRVAR
(
append_doc
,
"L.append(object) -- append object to end"
);
"L.append(object) -- append object to end"
);
PyDoc_STRVAR
(
extend_doc
,
PyDoc_STRVAR
(
extend_doc
,
...
@@ -2350,9 +2367,11 @@ static PyMethodDef list_methods[] = {
...
@@ -2350,9 +2367,11 @@ static PyMethodDef list_methods[] = {
{
"__getitem__"
,
(
PyCFunction
)
list_subscript
,
METH_O
|
METH_COEXIST
,
getitem_doc
},
{
"__getitem__"
,
(
PyCFunction
)
list_subscript
,
METH_O
|
METH_COEXIST
,
getitem_doc
},
{
"__reversed__"
,(
PyCFunction
)
list_reversed
,
METH_NOARGS
,
reversed_doc
},
{
"__reversed__"
,(
PyCFunction
)
list_reversed
,
METH_NOARGS
,
reversed_doc
},
{
"__sizeof__"
,
(
PyCFunction
)
list_sizeof
,
METH_NOARGS
,
sizeof_doc
},
{
"__sizeof__"
,
(
PyCFunction
)
list_sizeof
,
METH_NOARGS
,
sizeof_doc
},
{
"clear"
,
(
PyCFunction
)
listclear
,
METH_NOARGS
,
clear_doc
},
{
"copy"
,
(
PyCFunction
)
listcopy
,
METH_NOARGS
,
copy_doc
},
{
"append"
,
(
PyCFunction
)
listappend
,
METH_O
,
append_doc
},
{
"append"
,
(
PyCFunction
)
listappend
,
METH_O
,
append_doc
},
{
"insert"
,
(
PyCFunction
)
listinsert
,
METH_VARARGS
,
insert_doc
},
{
"insert"
,
(
PyCFunction
)
listinsert
,
METH_VARARGS
,
insert_doc
},
{
"extend"
,
(
PyCFunction
)
listextend
,
METH_O
,
extend_doc
},
{
"extend"
,
(
PyCFunction
)
listextend
,
METH_O
,
extend_doc
},
{
"pop"
,
(
PyCFunction
)
listpop
,
METH_VARARGS
,
pop_doc
},
{
"pop"
,
(
PyCFunction
)
listpop
,
METH_VARARGS
,
pop_doc
},
{
"remove"
,
(
PyCFunction
)
listremove
,
METH_O
,
remove_doc
},
{
"remove"
,
(
PyCFunction
)
listremove
,
METH_O
,
remove_doc
},
{
"index"
,
(
PyCFunction
)
listindex
,
METH_VARARGS
,
index_doc
},
{
"index"
,
(
PyCFunction
)
listindex
,
METH_VARARGS
,
index_doc
},
...
...
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