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
7aebb64b
Kaydet (Commit)
7aebb64b
authored
Şub 09, 2008
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Document how to use Set and MutableSet as a mixin.
üst
74b6495b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
3 deletions
+20
-3
collections.rst
Doc/library/collections.rst
+18
-1
_abcoll.py
Lib/_abcoll.py
+2
-2
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
7aebb64b
...
...
@@ -58,7 +58,7 @@ ABC Inherits Abstract Methods Mixin M
``insert``, ``remove``, and ``__iadd__``
and ``__len__``
:class:`Set`
:class:`Sized`, ``__len__``, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
:class:`Set`
\(1) \(2)
:class:`Sized`, ``__len__``, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
:class:`Iterable`, ``__iter__``, and ``__gt__``, ``__ge__``, ``__and__``, ``__or__``
:class:`Container` ``__contains__`` ``__sub__``, ``__xor__``, and ``isdisjoint``
...
...
@@ -100,6 +100,23 @@ The ABC supplies the remaining methods such as :meth:`__and__` and
s2 = ListBasedSet('defghi')
overlap = s1 & s2 # The __and__() method is supported automatically
Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
(1)
Since some set operations create new sets, the default mixin methods need
a way to create new instances from an iterable. The class constructor is
assumed to have a signature in the form ``ClassName(iterable)``.
That assumption is factored-out to a singleinternal classmethod called
:meth:`_from_iterable` which calls ``cls(iterable)`` to produce a new set.
If the :class:`Set` mixin is being used in a class with a different
constructor signature, you will need to override :meth:`from_iterable`
with a classmethod that can construct new instances from
an iterable argument.
(2)
To override the comparisons (presumably for speed, as the
semantics are fixed), redefine :meth:`__le__` and
then the other operations will automatically follow suit.
(For more about ABCs, see the :mod:`abc` module and :pep:`3119`.)
...
...
Lib/_abcoll.py
Dosyayı görüntüle @
7aebb64b
...
...
@@ -207,9 +207,9 @@ class Set(Sized, Iterable, Container):
'''Construct an instance of the class from any iterable input.
Must override this method if the class constructor signature
will not accept a frozenset
for an input.
does not accept an iterable
for an input.
'''
return
cls
(
frozenset
(
it
)
)
return
cls
(
it
)
def
__and__
(
self
,
other
):
if
not
isinstance
(
other
,
Iterable
):
...
...
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