-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Python 2.6 can't read sets pickled with Python 3.0 #47925
Comments
After pickling a set of ints with Python 3.0 and pickle protocol 2: [hagenf@chage ~]$ python3.0
Python 3.0b3 (r30b3:65927, Aug 21 2008, 11:48:29)
[GCC 4.1.0 20060304 (Red Hat 4.1.0-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> f = open("test", "wb")
>>> pickle.dump({1,2,3}, f, 2)
>>> f.close() I get the following error when trying to read this with Python 2.6: [hagenf@chage ~]$ python
Python 2.6b3 (r26b3:65922, Aug 21 2008, 11:42:25)
[GCC 4.1.0 20060304 (Red Hat 4.1.0-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> f = open("test", "rb")
>>> pickle.load(f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/MC/hagenf/local/lib/python2.6/pickle.py", line 1370, in load
return Unpickler(file).load()
File "/home/MC/hagenf/local/lib/python2.6/pickle.py", line 858, in load
dispatch[key](self)
File "/home/MC/hagenf/local/lib/python2.6/pickle.py", line 1090, in
load_global
klass = self.find_class(module, name)
File "/home/MC/hagenf/local/lib/python2.6/pickle.py", line 1124, in
find_class
__import__(module)
ImportError: No module named builtins |
Well, this is obviously caused by renaming "__builtin__" to "builtins" But aside from that, wouldn't it be more consistent to have opcodes for |
Hagen, Index: Lib/pickle.py def find_class(self, module, name):
# Subclasses may override this
+ if module == "builtins":
+ module = "__builtin__"
__import__(module)
mod = sys.modules[module]
klass = getattr(mod, name) I think a dict mapping the moved modules would work better, perhaps |
Well, Python <= 2.5 still wouldn't be able to unpickle those built in |
FWIW, there's a mapping of 2.6:3.0 modules in lib2to3: from lib2to3.fixes.fix_imports import MAPPING The attached patch uses that for a quick and dirty way of loading 3.0 |
Was it really intended that 3.0 pickles unpickle on 2.6? |
He used protocol 2, so he explicitly asked for something inpickleable |
I agree with Antoine, protocols <= 2 should remain compatible with |
Would it would be sufficient to add a function in the pickletools |
Superseded by issue bpo-6137. |
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: