You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
678 B
Python
31 lines
678 B
Python
from __future__ import division, print_function
|
|
|
|
import cPickle as pickle
|
|
|
|
|
|
class SomeObject(object):
|
|
def __eq__(self, other):
|
|
"""Default __eq__ would always return False."""
|
|
return True
|
|
|
|
pass
|
|
|
|
a = (1, 2)
|
|
b = "zwei"
|
|
c = [3, 4, 5, 6]
|
|
d = c
|
|
e = SomeObject()
|
|
f = e
|
|
before_pickle = [a, b, c, d, e, f]
|
|
|
|
after_pickle = pickle.loads(pickle.dumps(before_pickle))
|
|
|
|
# should get equal objects, but not the same:
|
|
for i in range(6):
|
|
assert before_pickle[i] == after_pickle[i]
|
|
assert id(before_pickle[i]) != id(after_pickle[i])
|
|
|
|
# same objects stay the same:
|
|
assert id(after_pickle[2]) == id(after_pickle[3])
|
|
assert id(after_pickle[4]) == id(after_pickle[5])
|