diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a32a9929..0b1ebe30 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 `__). + + v4.39.0 (2025-04-29) -------------------- diff --git a/jsonargparse/_common.py b/jsonargparse/_common.py index 6367d51c..8c9625c3 100644 --- a/jsonargparse/_common.py +++ b/jsonargparse/_common.py @@ -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 diff --git a/jsonargparse_tests/test_parsing_settings.py b/jsonargparse_tests/test_parsing_settings.py index 2c51bbd4..3057969f 100644 --- a/jsonargparse_tests/test_parsing_settings.py +++ b/jsonargparse_tests/test_parsing_settings.py @@ -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)