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
9117c751
Kaydet (Commit)
9117c751
authored
Agu 22, 2010
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #9214: Fix set operations on KeysView and ItemsView.
üst
a52bae75
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
1 deletion
+37
-1
_abcoll.py
Lib/_abcoll.py
+8
-0
test_collections.py
Lib/test/test_collections.py
+26
-1
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/_abcoll.py
Dosyayı görüntüle @
9117c751
...
@@ -393,6 +393,10 @@ class MappingView(Sized):
...
@@ -393,6 +393,10 @@ class MappingView(Sized):
class
KeysView
(
MappingView
,
Set
):
class
KeysView
(
MappingView
,
Set
):
@classmethod
def
_from_iterable
(
self
,
it
):
return
set
(
it
)
def
__contains__
(
self
,
key
):
def
__contains__
(
self
,
key
):
return
key
in
self
.
_mapping
return
key
in
self
.
_mapping
...
@@ -405,6 +409,10 @@ KeysView.register(dict_keys)
...
@@ -405,6 +409,10 @@ KeysView.register(dict_keys)
class
ItemsView
(
MappingView
,
Set
):
class
ItemsView
(
MappingView
,
Set
):
@classmethod
def
_from_iterable
(
self
,
it
):
return
set
(
it
)
def
__contains__
(
self
,
item
):
def
__contains__
(
self
,
item
):
key
,
value
=
item
key
,
value
=
item
try
:
try
:
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
9117c751
...
@@ -13,7 +13,7 @@ import sys
...
@@ -13,7 +13,7 @@ import sys
from
collections
import
Hashable
,
Iterable
,
Iterator
from
collections
import
Hashable
,
Iterable
,
Iterator
from
collections
import
Sized
,
Container
,
Callable
from
collections
import
Sized
,
Container
,
Callable
from
collections
import
Set
,
MutableSet
from
collections
import
Set
,
MutableSet
from
collections
import
Mapping
,
MutableMapping
from
collections
import
Mapping
,
MutableMapping
,
KeysView
,
ItemsView
,
UserDict
from
collections
import
Sequence
,
MutableSequence
from
collections
import
Sequence
,
MutableSequence
from
collections
import
ByteString
from
collections
import
ByteString
...
@@ -548,6 +548,31 @@ class TestCollectionABCs(ABCTestCase):
...
@@ -548,6 +548,31 @@ class TestCollectionABCs(ABCTestCase):
self
.
validate_abstract_methods
(
MutableMapping
,
'__contains__'
,
'__iter__'
,
'__len__'
,
self
.
validate_abstract_methods
(
MutableMapping
,
'__contains__'
,
'__iter__'
,
'__len__'
,
'__getitem__'
,
'__setitem__'
,
'__delitem__'
)
'__getitem__'
,
'__setitem__'
,
'__delitem__'
)
def
test_MutableMapping_subclass
(
self
):
# Test issue 9214
mymap
=
UserDict
()
mymap
[
'red'
]
=
5
self
.
assertIsInstance
(
mymap
.
keys
(),
Set
)
self
.
assertIsInstance
(
mymap
.
keys
(),
KeysView
)
self
.
assertIsInstance
(
mymap
.
items
(),
Set
)
self
.
assertIsInstance
(
mymap
.
items
(),
ItemsView
)
mymap
=
UserDict
()
mymap
[
'red'
]
=
5
z
=
mymap
.
keys
()
|
{
'orange'
}
self
.
assertIsInstance
(
z
,
set
)
list
(
z
)
mymap
[
'blue'
]
=
7
# Shouldn't affect 'z'
self
.
assertEqual
(
sorted
(
z
),
[
'orange'
,
'red'
])
mymap
=
UserDict
()
mymap
[
'red'
]
=
5
z
=
mymap
.
items
()
|
{(
'orange'
,
3
)}
self
.
assertIsInstance
(
z
,
set
)
list
(
z
)
mymap
[
'blue'
]
=
7
# Shouldn't affect 'z'
self
.
assertEqual
(
sorted
(
z
),
[(
'orange'
,
3
),
(
'red'
,
5
)])
def
test_Sequence
(
self
):
def
test_Sequence
(
self
):
for
sample
in
[
tuple
,
list
,
bytes
,
str
]:
for
sample
in
[
tuple
,
list
,
bytes
,
str
]:
self
.
assertIsInstance
(
sample
(),
Sequence
)
self
.
assertIsInstance
(
sample
(),
Sequence
)
...
...
Misc/NEWS
Dosyayı görüntüle @
9117c751
...
@@ -66,6 +66,9 @@ Core and Builtins
...
@@ -66,6 +66,9 @@ Core and Builtins
Extensions
Extensions
----------
----------
- Issue #9214: Set operations on a KeysView or ItemsView in collections
now correctly return a set. (Patch by Eli Bendersky.)
- Issue #5737: Add Solaris-specific mnemonics in the errno module. Patch by
- Issue #5737: Add Solaris-specific mnemonics in the errno module. Patch by
Matthew Ahrens.
Matthew Ahrens.
...
...
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