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
af3b39a1
Kaydet (Commit)
af3b39a1
authored
Şub 18, 2005
tarafından
Walter Dörwald
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add support for negative indices in UserString.MutableString.__setitem__
and UserString.MutableString.__delitem__.
üst
612df8e2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
7 deletions
+14
-7
UserString.py
Lib/UserString.py
+4
-0
test_userstring.py
Lib/test/test_userstring.py
+7
-7
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/UserString.py
Dosyayı görüntüle @
af3b39a1
...
...
@@ -146,9 +146,13 @@ class MutableString(UserString):
def
__hash__
(
self
):
raise
TypeError
,
"unhashable type (it is mutable)"
def
__setitem__
(
self
,
index
,
sub
):
if
index
<
0
:
index
+=
len
(
self
.
data
)
if
index
<
0
or
index
>=
len
(
self
.
data
):
raise
IndexError
self
.
data
=
self
.
data
[:
index
]
+
sub
+
self
.
data
[
index
+
1
:]
def
__delitem__
(
self
,
index
):
if
index
<
0
:
index
+=
len
(
self
.
data
)
if
index
<
0
or
index
>=
len
(
self
.
data
):
raise
IndexError
self
.
data
=
self
.
data
[:
index
]
+
self
.
data
[
index
+
1
:]
def
__setslice__
(
self
,
start
,
end
,
sub
):
...
...
Lib/test/test_userstring.py
Dosyayı görüntüle @
af3b39a1
...
...
@@ -52,20 +52,20 @@ class MutableStringTest(UserStringTest):
def
test_setitem
(
self
):
s
=
self
.
type2test
(
"foo"
)
self
.
assertRaises
(
IndexError
,
s
.
__setitem__
,
-
1
,
"bar"
)
self
.
assertRaises
(
IndexError
,
s
.
__setitem__
,
-
4
,
"bar"
)
self
.
assertRaises
(
IndexError
,
s
.
__setitem__
,
3
,
"bar"
)
s
[
-
1
]
=
"bar"
self
.
assertEqual
(
s
,
"fobar"
)
s
[
0
]
=
"bar"
self
.
assertEqual
(
s
,
"baroo"
)
s
[
4
]
=
"foo"
self
.
assertEqual
(
s
,
"barofoo"
)
self
.
assertEqual
(
s
,
"barobar"
)
def
test_delitem
(
self
):
s
=
self
.
type2test
(
"foo"
)
self
.
assertRaises
(
IndexError
,
s
.
__delitem__
,
-
1
)
self
.
assertRaises
(
IndexError
,
s
.
__delitem__
,
-
4
)
self
.
assertRaises
(
IndexError
,
s
.
__delitem__
,
3
)
del
s
[
-
1
]
self
.
assertEqual
(
s
,
"fo"
)
del
s
[
0
]
self
.
assertEqual
(
s
,
"oo"
)
del
s
[
1
]
self
.
assertEqual
(
s
,
"o"
)
del
s
[
0
]
self
.
assertEqual
(
s
,
""
)
...
...
Misc/NEWS
Dosyayı görüntüle @
af3b39a1
...
...
@@ -152,6 +152,9 @@ Library
-
The
reconvert
.
quote
function
can
now
emit
triple
-
quoted
strings
.
The
reconvert
module
now
has
some
simple
documentation
.
-
``
UserString
.
MutableString
``
now
supports
negative
indices
in
``
__setitem__
``
and
``
__delitem__
``
Build
-----
...
...
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