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
584e8aed
Kaydet (Commit)
584e8aed
authored
May 05, 2016
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 26915: Add identity checks to the collections ABC __contains__ methods.
üst
d7062de9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
4 deletions
+30
-4
_collections_abc.py
Lib/_collections_abc.py
+4
-3
test_collections.py
Lib/test/test_collections.py
+21
-1
NEWS
Misc/NEWS
+5
-0
No files found.
Lib/_collections_abc.py
Dosyayı görüntüle @
584e8aed
...
...
@@ -689,7 +689,7 @@ class ItemsView(MappingView, Set):
except
KeyError
:
return
False
else
:
return
v
==
value
return
v
is
value
or
v
==
value
def
__iter__
(
self
):
for
key
in
self
.
_mapping
:
...
...
@@ -704,7 +704,8 @@ class ValuesView(MappingView):
def
__contains__
(
self
,
value
):
for
key
in
self
.
_mapping
:
if
value
==
self
.
_mapping
[
key
]:
v
=
self
.
_mapping
[
key
]
if
v
is
value
or
v
==
value
:
return
True
return
False
...
...
@@ -839,7 +840,7 @@ class Sequence(Sized, Reversible, Container):
def
__contains__
(
self
,
value
):
for
v
in
self
:
if
v
==
value
:
if
v
is
value
or
v
==
value
:
return
True
return
False
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
584e8aed
...
...
@@ -23,7 +23,7 @@ from collections.abc import Awaitable, Coroutine, AsyncIterator, AsyncIterable
from
collections.abc
import
Hashable
,
Iterable
,
Iterator
,
Generator
,
Reversible
from
collections.abc
import
Sized
,
Container
,
Callable
from
collections.abc
import
Set
,
MutableSet
from
collections.abc
import
Mapping
,
MutableMapping
,
KeysView
,
ItemsView
from
collections.abc
import
Mapping
,
MutableMapping
,
KeysView
,
ItemsView
,
ValuesView
from
collections.abc
import
Sequence
,
MutableSequence
from
collections.abc
import
ByteString
...
...
@@ -1074,6 +1074,26 @@ class TestCollectionABCs(ABCTestCase):
self
.
assertFalse
(
ncs
>
cs
)
self
.
assertTrue
(
ncs
>=
cs
)
def
test_issue26915
(
self
):
# Container membership test should check identity first
class
CustomEqualObject
:
def
__eq__
(
self
,
other
):
return
False
class
CustomSequence
(
list
):
def
__contains__
(
self
,
value
):
return
Sequence
.
__contains__
(
self
,
value
)
nan
=
float
(
'nan'
)
obj
=
CustomEqualObject
()
containers
=
[
CustomSequence
([
nan
,
obj
]),
ItemsView
({
1
:
nan
,
2
:
obj
}),
ValuesView
({
1
:
nan
,
2
:
obj
})
]
for
container
in
containers
:
for
elem
in
container
:
self
.
assertIn
(
elem
,
container
)
def
assertSameSet
(
self
,
s1
,
s2
):
# coerce both to a real set then check equality
self
.
assertSetEqual
(
set
(
s1
),
set
(
s2
))
...
...
Misc/NEWS
Dosyayı görüntüle @
584e8aed
...
...
@@ -268,6 +268,11 @@ Library
- Issue #26873: xmlrpc now raises ResponseError on unsupported type tags
instead of silently return incorrect result.
- Issue #26915: The __contains__ methods in the collections ABCs now check
for identity before checking equality. This better matches the behavior
of the concrete classes, allows sensible handling of NaNs, and makes it
easier to reason about container invariants.
- Issue #26711: Fixed the comparison of plistlib.Data with other types.
- Issue #24114: Fix an uninitialized variable in `ctypes.util`.
...
...
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