Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cd58b8f5
Commit
cd58b8f5
authored
Nov 13, 2002
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getstate and setstate implementation to concrete set classes.
parent
66abcee9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
Lib/sets.py
Lib/sets.py
+12
-0
Lib/test/test_sets.py
Lib/test/test_sets.py
+9
-1
No files found.
Lib/sets.py
View file @
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
View file @
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