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

Fix parameter resolving falling back to assumptions resolver for optional Union types #498

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Added
- Support for ``TypedDict`` (`#457
<https://github.com/omni-us/jsonargparse/issues/457>`__).

Fixed
^^^^^
- Parameter resolving falling back to assumptions resolver for optional
``Union`` types.


v4.28.0 (2024-04-17)
--------------------
Expand Down
13 changes: 8 additions & 5 deletions jsonargparse/_parameter_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,14 @@ def is_param_subclass_instance_default(param: ParamData) -> bool:

annotation = get_optional_arg(param.annotation)
class_types = get_subclass_types(annotation)
return (class_types and isinstance(param.default, class_types)) or (
is_lambda(param.default)
and ActionTypeHint.is_callable_typehint(annotation, all_subtypes=False)
and annotation.__args__
and ActionTypeHint.is_subclass_typehint(annotation.__args__[-1], all_subtypes=False)
return bool(
(class_types and isinstance(param.default, class_types))
or (
is_lambda(param.default)
and ActionTypeHint.is_callable_typehint(annotation, all_subtypes=False)
and getattr(annotation, "__args__", None)
and ActionTypeHint.is_subclass_typehint(annotation.__args__[-1], all_subtypes=False)
)
)


Expand Down