Skip to content

Commit 14b4842

Browse files
committed
Fixed dump not working for partial callable with return instance pytorch-lightning#15340 (comment).
1 parent ac790ba commit 14b4842

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ The semantic versioning only considers the public API as described in
1212
paths are considered internals and can change in minor and patch releases.
1313

1414

15+
v4.20.1 (2023-02-??)
16+
--------------------
17+
18+
Fixed
19+
^^^^^
20+
- Dump not working for partial callable with return instance
21+
`pytorch-lightning#15340 (comment)
22+
<https://github.com/Lightning-AI/lightning/issues/15340#issuecomment-1439203008>`__.
23+
24+
1525
v4.20.0 (2023-02-20)
1626
--------------------
1727

@@ -54,7 +64,6 @@ v4.19.0 (2022-12-27)
5464

5565
Added
5666
^^^^^
57-
- ``add_dataclass_arguments`` now supports the ``fail_untyped`` parameter
5867
- ``CLI`` now supports the ``fail_untyped`` and ``parser_class`` parameters.
5968
- ``bytes`` and ``bytearray`` registered on first use and decodes from standard
6069
Base64.

jsonargparse/typehints.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,8 @@ def adapt_typehints(
722722
elif typehint_origin in callable_origin_types or typehint in callable_origin_types:
723723
if serialize:
724724
if is_subclass_spec(val):
725-
val = adapt_class_type(val, True, False, sub_add_kwargs)
725+
val, _, num_partial_args = adapt_partial_callable_class(typehint, val)
726+
val = adapt_class_type(val, True, False, sub_add_kwargs, skip_args=num_partial_args)
726727
else:
727728
val = object_path_serializer(val)
728729
else:

jsonargparse_tests/test_typehints.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ def __init__(self, *args, **kwargs):
838838
self.assertIsInstance(optim, Adam)
839839
self.assertEqual(optim.params, [4.5, 6.7])
840840
self.assertEqual(optim.lr, 0.01)
841+
dump = parser.dump(cfg)
842+
self.assertEqual(yaml.safe_load(dump), cfg.as_dict())
841843

842844
self.assertEqual(cfg, parser.parse_args(['--optimizer=Adam', '--optimizer.lr=0.01']))
843845

0 commit comments

Comments
 (0)