-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unpickling does not intern attribute names #49334
Comments
Instance attribute names are normally interned - this is done in >>> import pickle
>>> class C(object):
... def __init__(self, x):
... self.long_attribute_name = x
...
>>> len(pickle.dumps([pickle.loads(pickle.dumps(C(None),
pickle.HIGHEST_PROTOCOL)) for i in range(100)],
pickle.HIGHEST_PROTOCOL))
3658
>>> len(pickle.dumps([C(None) for i in range(100)],
pickle.HIGHEST_PROTOCOL))
1441
>>> Interning the strings on unpickling makes the pickles smaller, and at |
Either my browser got crazy, or you uploaded the same patch (.py) twice. |
The patch for cPickle doesn't do the same thing as the pickle one. In |
Are you sure? I may not have enough context in my diff, which I -jake On Jan 27, 2009, at 6:54 PM, Alexandre Vassalotti wrote:
|
Oh, you are right. I was looking at py3k's version of pickle, which uses |
Why do you call PyString_AsString() followed by PyString_FromString()? Besides, it would be nice to add a test. |
The fromstring/asstring dance was due to my incomplete understanding of What sort of test did you have in mind? |
The test should check that the unpickled strings have been interned. |
In your patch, I'm not sure where the |
To give an example of what the test could check: >>> class C(object):
... def __init__(self):
... self.some_long_attribute_name = 5
...
>>> c = C()
>>> c.__dict__
{'some_long_attribute_name': 5}
>>> sorted(map(id, c.__dict__))
[140371243499696]
>>> import pickle
>>> d = pickle.loads(pickle.dumps(c, -1))
>>> d
<__main__.C object at 0x7faaba1b0390>
>>> d.__dict__
{'some_long_attribute_name': 5}
>>> sorted(map(id, d.__dict__))
[140371243501232] The |
Ugh. Clearly I didn't check to see if it worked or not, as it didn't even |
Jake, are you string working on a test? |
(s/string/still/, of course...) |
This fell through the cracks. But the following unit test seems like it |
Thanks, I'll take a look very soon. |
Committed in r72223, r72224. Thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: