summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-05-02 21:13:23 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-05-02 21:13:23 (GMT)
commit7430989cdadfb5aacef6909a3e2c033a0209699b (patch)
tree7698e15757d641da2d648cde43438a0c6bf5ac02 /Lib/test
parent2b42c29a5040b39e481d976f4ec3d6aa425ab4cc (diff)
downloadcpython-7430989cdadfb5aacef6909a3e2c033a0209699b.zip
cpython-7430989cdadfb5aacef6909a3e2c033a0209699b.tar.gz
cpython-7430989cdadfb5aacef6909a3e2c033a0209699b.tar.bz2
Isue #5084: unpickling now interns the attribute names of pickled objects,
saving memory and avoiding growth in size of subsequent pickles. Proposal and original patch by Jake McGuire.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/pickletester.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 4ffa702..bc0be1f 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -938,6 +938,20 @@ class AbstractPickleTests(unittest.TestCase):
"Failed protocol %d: %r != %r"
% (proto, obj, loaded))
+ def test_attribute_name_interning(self):
+ # Test that attribute names of pickled objects are interned when
+ # unpickling.
+ for proto in protocols:
+ x = C()
+ x.foo = 42
+ x.bar = "hello"
+ s = self.dumps(x, proto)
+ y = self.loads(s)
+ x_keys = sorted(x.__dict__)
+ y_keys = sorted(y.__dict__)
+ for x_key, y_key in zip(x_keys, y_keys):
+ self.assertIs(x_key, y_key)
+
# Test classes for reduce_ex