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
cd58b8f5
Kaydet (Commit)
cd58b8f5
authored
Kas 13, 2002
tarafından
Jeremy Hylton
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add getstate and setstate implementation to concrete set classes.
üst
66abcee9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
sets.py
Lib/sets.py
+12
-0
test_sets.py
Lib/test/test_sets.py
+9
-1
No files found.
Lib/sets.py
Dosyayı görüntüle @
cd58b8f5
...
@@ -366,6 +366,11 @@ class ImmutableSet(BaseSet):
...
@@ -366,6 +366,11 @@ class ImmutableSet(BaseSet):
self
.
_hashcode
=
self
.
_compute_hash
()
self
.
_hashcode
=
self
.
_compute_hash
()
return
self
.
_hashcode
return
self
.
_hashcode
def
__getstate__
(
self
):
return
self
.
_data
,
self
.
_hashcode
def
__setstate__
(
self
,
state
):
self
.
_data
,
self
.
_hashcode
=
state
class
Set
(
BaseSet
):
class
Set
(
BaseSet
):
""" Mutable set class."""
""" Mutable set class."""
...
@@ -380,6 +385,13 @@ class Set(BaseSet):
...
@@ -380,6 +385,13 @@ class Set(BaseSet):
if
iterable
is
not
None
:
if
iterable
is
not
None
:
self
.
_update
(
iterable
)
self
.
_update
(
iterable
)
def
__getstate__
(
self
):
# getstate's results are ignored if it is not
return
self
.
_data
,
def
__setstate__
(
self
,
data
):
self
.
_data
,
=
data
def
__hash__
(
self
):
def
__hash__
(
self
):
"""A Set cannot be hashed."""
"""A Set cannot be hashed."""
# We inherit object.__hash__, so we must deny this explicitly
# We inherit object.__hash__, so we must deny this explicitly
...
...
Lib/test/test_sets.py
Dosyayı görüntüle @
cd58b8f5
#!/usr/bin/env python
#!/usr/bin/env python
import
unittest
,
operator
,
copy
import
unittest
,
operator
,
copy
,
pickle
from
sets
import
Set
,
ImmutableSet
from
sets
import
Set
,
ImmutableSet
from
test
import
test_support
from
test
import
test_support
...
@@ -74,6 +74,14 @@ class TestBasicOps(unittest.TestCase):
...
@@ -74,6 +74,14 @@ class TestBasicOps(unittest.TestCase):
for
v
in
self
.
set
:
for
v
in
self
.
set
:
self
.
assert_
(
v
in
self
.
values
)
self
.
assert_
(
v
in
self
.
values
)
def
test_pickling
(
self
):
p
=
pickle
.
dumps
(
self
.
set
)
print
repr
(
p
)
copy
=
pickle
.
loads
(
p
)
repr
(
copy
)
self
.
assertEqual
(
self
.
set
,
copy
,
"
%
s !=
%
s"
%
(
self
.
set
,
copy
))
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
class
TestBasicOpsEmpty
(
TestBasicOps
):
class
TestBasicOpsEmpty
(
TestBasicOps
):
...
...
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