Skip to content
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

Unable to pickle itertools.chain.from_iterable #56

Closed
Futrell opened this issue Mar 8, 2016 · 2 comments · Fixed by #57
Closed

Unable to pickle itertools.chain.from_iterable #56

Futrell opened this issue Mar 8, 2016 · 2 comments · Fixed by #57

Comments

@Futrell
Copy link
Contributor

Futrell commented Mar 8, 2016

Using cloudpickle as cloned from the repo just now, Python 2.7.11:

Python 2.7.11 (default, Mar  4 2016, 11:10:11)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cloudpickle
>>> import itertools
>>> cloudpickle.dumps(itertools.chain.from_iterable)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cloudpickle/cloudpickle.py", line 629, in dumps
    cp.dump(obj)
  File "cloudpickle/cloudpickle.py", line 107, in dump
    return Pickler.dump(self, obj)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
    self.save(obj)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "cloudpickle/cloudpickle.py", line 330, in save_builtin_function
    return self.save_function(obj)
  File "cloudpickle/cloudpickle.py", line 203, in save_function
    or getattr(obj.__code__, 'co_filename', None) == '<stdin>'
AttributeError: 'builtin_function_or_method' object has no attribute '__code__'

I get the same result on Python 3.5.1.

@Futrell
Copy link
Contributor Author

Futrell commented Mar 8, 2016

This seems to be a general property of builtin_function_or_methods which come in as attributes of objects. E.g., I get the error for cloudpickle.dumps(object.__new__), but no error for cloudpickle.dumps(print).

Under PyPy there is no error using cloudpickle to pickle any of these functions.

@ogrisel
Copy link
Contributor

ogrisel commented Mar 9, 2016

Could you please open a PR with a non-regression test and the fix? I think we just need to pass through to regular pickle when not hasattr(obj, '__code__').

Futrell added a commit to Futrell/cloudpickle that referenced this issue Mar 9, 2016
@rgbkrk rgbkrk closed this as completed in #57 Mar 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants