Skip to content
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
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ The semantic versioning only considers the public API as described in
paths are considered internals and can change in minor and patch releases.


v4.40.0 (2025-05-??)
--------------------

Fixed
^^^^^
- ``set_parsing_settings(validate_defaults=True)`` fails when the parser has a
config action (`#718 <https://github.com/omni-us/jsonargparse/pull/718>`__).


v4.39.0 (2025-04-29)
--------------------

Expand Down
4 changes: 2 additions & 2 deletions jsonargparse/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ def get_parsing_setting(name: str):


def validate_default(container: ActionsContainer, action: argparse.Action):
if not isinstance(action, Action) or not get_parsing_setting("validate_defaults") or action.default is None:
if action.default is None or not get_parsing_setting("validate_defaults") or not hasattr(action, "_check_type"):
return
try:
with parser_context(parent_parser=container):
default = action.default
action.default = None
action.default = action._check_type_(default)
action.default = action._check_type_(default) # type: ignore[attr-defined]
except Exception as ex:
raise ValueError(f"Default value is not valid: {ex}") from ex

Expand Down
1 change: 1 addition & 0 deletions jsonargparse_tests/test_parsing_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_set_validate_defaults_failure():
def test_validate_defaults_success(parser):
set_parsing_settings(validate_defaults=True)

parser.add_argument("--config", action="config")
parser.add_argument("--num", type=int, default=1)
parser.add_argument("--untyped", default=2)

Expand Down