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
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Fixed
^^^^^
- Stubs resolver in some cases failing with maximum recursion error (`#770
<https://github.com/omni-us/jsonargparse/pull/770>`__).
- ``dataclass`` with default failing when ``validate_defaults=True`` (`#771
<https://github.com/omni-us/jsonargparse/pull/771>`__).


v4.41.0 (2025-09-04)
Expand Down
4 changes: 4 additions & 0 deletions jsonargparse/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def validate_default(container: ActionsContainer, action: argparse.Action):
if action.default is None or not get_parsing_setting("validate_defaults") or not hasattr(action, "_check_type"):
return
try:
from ._core import ArgumentGroup

if isinstance(container, ArgumentGroup):
container = container.parser # type: ignore[assignment]
with parser_context(parent_parser=container):
default = action.default
action.default = None
Expand Down
12 changes: 12 additions & 0 deletions jsonargparse_tests/test_parsing_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def test_validate_defaults_failure(parser):
parser.add_argument("--num", type=int, default="x")


@dataclass
class DataWithDefault:
param: str = "foo"


def test_validate_defaults_dataclass(parser):
set_parsing_settings(validate_defaults=True)

added_args = parser.add_class_arguments(DataWithDefault)
assert added_args == ["param"]


# parse_optionals_as_positionals


Expand Down