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
ec219ba1
Kaydet (Commit)
ec219ba1
authored
May 23, 2015
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #23086: Add start and stop arguments to the Sequence.index() mixin method.
üst
256613c6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
5 deletions
+69
-5
collections.abc.rst
Doc/library/collections.abc.rst
+14
-0
_collections_abc.py
Lib/_collections_abc.py
+15
-5
test_collections.py
Lib/test/test_collections.py
+35
-0
ACKS
Misc/ACKS
+1
-0
NEWS
Misc/NEWS
+4
-0
No files found.
Doc/library/collections.abc.rst
Dosyayı görüntüle @
ec219ba1
...
...
@@ -121,6 +121,20 @@ ABC Inherits from Abstract Methods Mixin
ABCs for read-only and mutable :term:`sequences <sequence>`.
Implementation note: Some of the mixin methods, such as
:meth:`__iter__`, :meth:`__reversed__` and :meth:`index`, make
repeated calls to the underlying :meth:`__getitem__` method.
Consequently, if :meth:`__getitem__` is implemented with constant
access speed, the mixin methods will have linear performance;
however, if the underlying method is linear (as it would be with a
linked list), the mixins will have quadratic performance and will
likely need to be overridden.
.. versionchanged:: 3.5
The index() method added support for *stop* and *start*
arguments.
.. class:: Set
MutableSet
...
...
Lib/_collections_abc.py
Dosyayı görüntüle @
ec219ba1
...
...
@@ -825,13 +825,23 @@ class Sequence(Sized, Iterable, Container):
for
i
in
reversed
(
range
(
len
(
self
))):
yield
self
[
i
]
def
index
(
self
,
value
):
'''S.index(value) -> integer -- return first index of value.
def
index
(
self
,
value
,
start
=
0
,
stop
=
None
):
'''S.index(value
, [start, [stop]]
) -> integer -- return first index of value.
Raises ValueError if the value is not present.
'''
for
i
,
v
in
enumerate
(
self
):
if
v
==
value
:
return
i
if
start
is
not
None
and
start
<
0
:
start
=
max
(
len
(
self
)
+
start
,
0
)
if
stop
is
not
None
and
stop
<
0
:
stop
+=
len
(
self
)
i
=
start
while
stop
is
None
or
i
<
stop
:
try
:
if
self
[
i
]
==
value
:
return
i
except
IndexError
:
break
i
+=
1
raise
ValueError
def
count
(
self
,
value
):
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
ec219ba1
...
...
@@ -1227,6 +1227,41 @@ class TestCollectionABCs(ABCTestCase):
self
.
validate_abstract_methods
(
Sequence
,
'__contains__'
,
'__iter__'
,
'__len__'
,
'__getitem__'
)
def
test_Sequence_mixins
(
self
):
class
SequenceSubclass
(
Sequence
):
def
__init__
(
self
,
seq
=
()):
self
.
seq
=
seq
def
__getitem__
(
self
,
index
):
return
self
.
seq
[
index
]
def
__len__
(
self
):
return
len
(
self
.
seq
)
# Compare Sequence.index() behavior to (list|str).index() behavior
def
assert_index_same
(
seq1
,
seq2
,
index_args
):
try
:
expected
=
seq1
.
index
(
*
index_args
)
except
ValueError
:
with
self
.
assertRaises
(
ValueError
):
seq2
.
index
(
*
index_args
)
else
:
actual
=
seq2
.
index
(
*
index_args
)
self
.
assertEqual
(
actual
,
expected
,
'
%
r.index
%
s'
%
(
seq1
,
index_args
))
for
ty
in
list
,
str
:
nativeseq
=
ty
(
'abracadabra'
)
indexes
=
[
-
10000
,
-
9999
]
+
list
(
range
(
-
3
,
len
(
nativeseq
)
+
3
))
seqseq
=
SequenceSubclass
(
nativeseq
)
for
letter
in
set
(
nativeseq
)
|
{
'z'
}:
assert_index_same
(
nativeseq
,
seqseq
,
(
letter
,))
for
start
in
range
(
-
3
,
len
(
nativeseq
)
+
3
):
assert_index_same
(
nativeseq
,
seqseq
,
(
letter
,
start
))
for
stop
in
range
(
-
3
,
len
(
nativeseq
)
+
3
):
assert_index_same
(
nativeseq
,
seqseq
,
(
letter
,
start
,
stop
))
def
test_ByteString
(
self
):
for
sample
in
[
bytes
,
bytearray
]:
self
.
assertIsInstance
(
sample
(),
ByteString
)
...
...
Misc/ACKS
Dosyayı görüntüle @
ec219ba1
...
...
@@ -660,6 +660,7 @@ Bill Janssen
Thomas Jarosch
Juhana Jauhiainen
Rajagopalasarma Jayakrishnan
Devin Jeanpierre
Zbigniew Jędrzejewski-Szmek
Julien Jehannet
Muhammad Jehanzeb
...
...
Misc/NEWS
Dosyayı görüntüle @
ec219ba1
...
...
@@ -73,6 +73,10 @@ Library
- Issue #23973: PEP 484: Add the typing module.
- Issue #23086: The collections.abc.Sequence() abstract base class added
*start* and *stop* parameters to the index() mixin.
Patch by Devin Jeanpierre.
- Issue #20035: Replaced the ``tkinter._fix`` module used for setting up the
Tcl/Tk environment on Windows with a private function in the ``_tkinter``
module that makes no permanent changes to the environment.
...
...
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