Skip to content

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

@lesteve

Description

@lesteve
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions