Repository: omni-us/jsonargparse
Pull request #718 (2025-05-01 06:40:53)

Fix validate_defaults=True fails when the parser has a config action
## What does this PR do?

Fixes https://github.com/omni-us/jsonargparse/issues/237#issuecomment-2840020852

## Before submitting

- [x] Did you read the [contributing guideline](https://github.com/omni-us/jsonargparse/blob/main/CONTRIBUTING.rst)?
- [n/a] Did you update **the documentation**? (readme and public docstrings)
- [x] Did you write **unit tests** such that there is 100% coverage on related code? (required for bug fixes and new features)
- [x] Did you verify that new and existing **tests pass locally**?
- [x] Did you make sure that all changes preserve **backward compatibility**?
- [x] Did you update **the CHANGELOG**? (not for typos, docs, test updates, or minor internal changes/refactors)


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/omni-us/jsonargparse/pull/718?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=omni-us) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 100.00%. Comparing base [(`24f0dcb`)](https://app.codecov.io/gh/omni-us/jsonargparse/commit/24f0dcb8bd79d2f40352d57ee51f2bad9c38efac?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=omni-us) to head [(`3f2afab`)](https://app.codecov.io/gh/omni-us/jsonargparse/commit/3f2afab1431184e0da883d23acca01862b1968da?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=omni-us).

:white_check_mark: All tests successful. No failed tests found.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##              main      #718   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         6839      6839           
=========================================
  Hits          6839      6839           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/omni-us/jsonargparse/pull/718?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=omni-us).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=omni-us).

sonarqubecloud[bot]: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=omni-us_jsonargparse&pullRequest=718) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=omni-us_jsonargparse&pullRequest=718&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=omni-us_jsonargparse&pullRequest=718&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=omni-us_jsonargparse&pullRequest=718&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=omni-us_jsonargparse&pullRequest=718&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=omni-us_jsonargparse&pullRequest=718&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=omni-us_jsonargparse&pullRequest=718)



Patch:
diff --git a/.readthedocs.yaml b/.readthedocs.yaml
index 961899b..5e6083c 100644
--- a/.readthedocs.yaml
+++ b/.readthedocs.yaml
@@ -4,7 +4,7 @@
 version: 2
 
 build:
-  os: ubuntu-22.04
+  os: ubuntu-24.04
   tools:
     python: "3.12"
 
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index a32a992..0b1ebe3 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 <https://github.com/omni-us/jsonargparse/pull/718>`__).
+
+
 v4.39.0 (2025-04-29)
 --------------------
 
diff --git a/jsonargparse/_common.py b/jsonargparse/_common.py
index 6367d51..8c9625c 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/pyproject.toml b/pyproject.toml
index 2f7767f..dc1f8f7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -116,7 +116,7 @@ dev = [
     "build>=0.10.0",
 ]
 doc = [
-    "Sphinx>=1.7.9,<8.0.0",
+    "Sphinx>=1.7.9",
     "sphinx-rtd-theme>=1.2.2",
     "autodocsumm>=0.1.10",
     "sphinx-autodoc-typehints>=1.19.5",


Test patch:
diff --git a/jsonargparse_tests/test_parsing_settings.py b/jsonargparse_tests/test_parsing_settings.py
index 2c51bbd..3057969 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)