Skip to content

TypeError when calling a pickled + unpickled function in __main__ with keyword-only argument #263

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

Closed
lesteve opened this issue Apr 23, 2019 · 1 comment · Fixed by #264
Closed

Comments

@lesteve
Copy link
Contributor

lesteve commented Apr 23, 2019

import cloudpickle

def func_with_kw_only_args(a, *, b=1):
    return a + b


new_func = cloudpickle.loads(cloudpickle.dumps(func_with_kw_only_args))
new_func(1)

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-ee6063f05eec> in <module>
      6 
      7 new_func = cloudpickle.loads(cloudpickle.dumps(func_with_kw_only_args))
----> 8 new_func(1)
      9 
     10 

TypeError: func_with_kw_only_args() missing 1 required keyword-only argument: 'b'

Original bug was seen in joblib: joblib/joblib#863

Note: there is no error when putting the function with keyword-only arguments in a Python module.

@pierreglaser
Copy link
Member

pierreglaser commented Apr 23, 2019

Yeah, apparently we forget to write the __kwdefaults__ attribute to func_with_kw_only_args's pickle. We just pass __defaults__, which seems to suffice except in the keyword-only argument case.

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