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
2835e37b
Kaydet (Commit)
2835e37b
authored
Şub 14, 2003
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
SF bug #663701: sets module review
Renamed hook methods to use the double underscore convention.
üst
e544f6f6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
11 deletions
+11
-11
libsets.tex
Doc/lib/libsets.tex
+4
-4
sets.py
Lib/sets.py
+7
-7
No files found.
Doc/lib/libsets.tex
Dosyayı görüntüle @
2835e37b
...
@@ -203,23 +203,23 @@ before being added as a set element.
...
@@ -203,23 +203,23 @@ before being added as a set element.
The mechanism is to always add a hashable element, or if it is not
The mechanism is to always add a hashable element, or if it is not
hashable, the element is checked to see if it has an
hashable, the element is checked to see if it has an
\method
{_
as
_
immutable
()
}
method which returns an immutable equivalent.
\method
{_
_
as
_
immutable
__
()
}
method which returns an immutable equivalent.
Since
\class
{
Set
}
objects have a
\method
{_
as
_
immutable
()
}
method
Since
\class
{
Set
}
objects have a
\method
{_
_
as
_
immutable
__
()
}
method
returning an instance of
\class
{
ImmutableSet
}
, it is possible to
returning an instance of
\class
{
ImmutableSet
}
, it is possible to
construct sets of sets.
construct sets of sets.
A similar mechanism is needed by the
\method
{__
contains
__
()
}
and
A similar mechanism is needed by the
\method
{__
contains
__
()
}
and
\method
{
remove()
}
methods which need to hash an element to check
\method
{
remove()
}
methods which need to hash an element to check
for membership in a set. Those methods check an element for hashability
for membership in a set. Those methods check an element for hashability
and, if not, check for a
\method
{_
as
_
temporarily
_
immutable
()
}
method
and, if not, check for a
\method
{_
_
as
_
temporarily
_
immutable
__
()
}
method
which returns the element wrapped by a class that provides temporary
which returns the element wrapped by a class that provides temporary
methods for
\method
{__
hash
__
()
}
,
\method
{__
eq
__
()
}
, and
\method
{__
ne
__
()
}
.
methods for
\method
{__
hash
__
()
}
,
\method
{__
eq
__
()
}
, and
\method
{__
ne
__
()
}
.
The alternate mechanism spares the need to build a separate copy of
The alternate mechanism spares the need to build a separate copy of
the original mutable object.
the original mutable object.
\class
{
Set
}
objects implement the
\method
{_
as
_
temporarily
_
immutable
()
}
\class
{
Set
}
objects implement the
\method
{_
_
as
_
temporarily
_
immutable
__
()
}
method which returns the
\class
{
Set
}
object wrapped by a new class
method which returns the
\class
{
Set
}
object wrapped by a new class
\class
{_
TemporarilyImmutableSet
}
.
\class
{_
TemporarilyImmutableSet
}
.
...
...
Lib/sets.py
Dosyayı görüntüle @
2835e37b
...
@@ -248,7 +248,7 @@ class BaseSet(object):
...
@@ -248,7 +248,7 @@ class BaseSet(object):
try
:
try
:
return
element
in
self
.
_data
return
element
in
self
.
_data
except
TypeError
:
except
TypeError
:
transform
=
getattr
(
element
,
"_
as_temporarily_immutable
"
,
None
)
transform
=
getattr
(
element
,
"_
_as_temporarily_immutable__
"
,
None
)
if
transform
is
None
:
if
transform
is
None
:
raise
# re-raise the TypeError exception we caught
raise
# re-raise the TypeError exception we caught
return
transform
()
in
self
.
_data
return
transform
()
in
self
.
_data
...
@@ -325,7 +325,7 @@ class BaseSet(object):
...
@@ -325,7 +325,7 @@ class BaseSet(object):
data
[
element
]
=
value
data
[
element
]
=
value
return
return
except
TypeError
:
except
TypeError
:
transform
=
getattr
(
element
,
"_
as_immutable
"
,
None
)
transform
=
getattr
(
element
,
"_
_as_immutable__
"
,
None
)
if
transform
is
None
:
if
transform
is
None
:
raise
# re-raise the TypeError exception we caught
raise
# re-raise the TypeError exception we caught
data
[
transform
()]
=
value
data
[
transform
()]
=
value
...
@@ -335,7 +335,7 @@ class BaseSet(object):
...
@@ -335,7 +335,7 @@ class BaseSet(object):
try
:
try
:
data
[
element
]
=
value
data
[
element
]
=
value
except
TypeError
:
except
TypeError
:
transform
=
getattr
(
element
,
"_
as_immutable
"
,
None
)
transform
=
getattr
(
element
,
"_
_as_immutable__
"
,
None
)
if
transform
is
None
:
if
transform
is
None
:
raise
# re-raise the TypeError exception we caught
raise
# re-raise the TypeError exception we caught
data
[
transform
()]
=
value
data
[
transform
()]
=
value
...
@@ -464,7 +464,7 @@ class Set(BaseSet):
...
@@ -464,7 +464,7 @@ class Set(BaseSet):
try
:
try
:
self
.
_data
[
element
]
=
True
self
.
_data
[
element
]
=
True
except
TypeError
:
except
TypeError
:
transform
=
getattr
(
element
,
"_
as_immutable
"
,
None
)
transform
=
getattr
(
element
,
"_
_as_immutable__
"
,
None
)
if
transform
is
None
:
if
transform
is
None
:
raise
# re-raise the TypeError exception we caught
raise
# re-raise the TypeError exception we caught
self
.
_data
[
transform
()]
=
True
self
.
_data
[
transform
()]
=
True
...
@@ -477,7 +477,7 @@ class Set(BaseSet):
...
@@ -477,7 +477,7 @@ class Set(BaseSet):
try
:
try
:
del
self
.
_data
[
element
]
del
self
.
_data
[
element
]
except
TypeError
:
except
TypeError
:
transform
=
getattr
(
element
,
"_
as_temporarily_immutable
"
,
None
)
transform
=
getattr
(
element
,
"_
_as_temporarily_immutable__
"
,
None
)
if
transform
is
None
:
if
transform
is
None
:
raise
# re-raise the TypeError exception we caught
raise
# re-raise the TypeError exception we caught
del
self
.
_data
[
transform
()]
del
self
.
_data
[
transform
()]
...
@@ -496,11 +496,11 @@ class Set(BaseSet):
...
@@ -496,11 +496,11 @@ class Set(BaseSet):
"""Remove and return an arbitrary set element."""
"""Remove and return an arbitrary set element."""
return
self
.
_data
.
popitem
()[
0
]
return
self
.
_data
.
popitem
()[
0
]
def
_
as_immutable
(
self
):
def
_
_as_immutable__
(
self
):
# Return a copy of self as an immutable set
# Return a copy of self as an immutable set
return
ImmutableSet
(
self
)
return
ImmutableSet
(
self
)
def
_
as_temporarily_immutable
(
self
):
def
_
_as_temporarily_immutable__
(
self
):
# Return self wrapped in a temporarily immutable set
# Return self wrapped in a temporarily immutable set
return
_TemporarilyImmutableSet
(
self
)
return
_TemporarilyImmutableSet
(
self
)
...
...
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