Description
The current implementation of adapt_class_type uses a locally defined function partial_instance as a wrapper:
https://github.com/omni-us/jsonargparse/blob/dcd0a5ae70d0ef5c7c053436375bcad9aa462c84/jsonargparse/_typehints.py#L1428-L1431
This causes a few issues with pickle serialization, as locally defined functions are not picklable.
Proposed Fix
Replace the custom function with a functools.partial, which is picklable:
return functools.partial(
instantiator_fn,
val_class,
**{**init_args, **dict_kwargs},
)
From what I see this should maintain the same behavior but ensures compatibility with serialization libraries. Can you think of any reason why not to support this?
Description
The current implementation of
adapt_class_typeuses a locally defined functionpartial_instanceas a wrapper:https://github.com/omni-us/jsonargparse/blob/dcd0a5ae70d0ef5c7c053436375bcad9aa462c84/jsonargparse/_typehints.py#L1428-L1431
This causes a few issues with pickle serialization, as locally defined functions are not picklable.
Proposed Fix
Replace the custom function with a
functools.partial, which is picklable:From what I see this should maintain the same behavior but ensures compatibility with serialization libraries. Can you think of any reason why not to support this?