Skip to content

Fix dump round-tripping, generic protocols, TypeVar types and extend subclass spec validation - #953

Merged
mauvilsa merged 2 commits into
mainfrom
fix-dump-roundtrip-and-type-resolution
Aug 12, 2026
Merged

Fix dump round-tripping, generic protocols, TypeVar types and extend subclass spec validation#953
mauvilsa merged 2 commits into
mainfrom
fix-dump-roundtrip-and-type-resolution

Conversation

@mauvilsa

Copy link
Copy Markdown
Owner

What does this PR do?

Two related groups of changes.

Subclass spec validation beyond Any — the validate_subclass_spec_in_any setting now also applies to
Unvalidated<...> and to dicts that don't validate their values, e.g. dict[str, Any]. For dicts the spec is only
validated and the value kept as a dict, which matters for unions such as Union[SomeClass, dict[str, Any]], where a
spec rejected by the class member would otherwise be silently swallowed by the dict member.

Fixes around dumping and type resolution:

  • dump and --print_config now round-trip values given as an import path to an instance. Previously the dump had a
    "not serializable" message unless the instance happened to be defined in the module of its class; now the import path
    the value was resolved from is remembered and dumped back.
  • Parsing the secret mask ********** as a SecretStr (both jsonargparse's and pydantic's) now fails, instead of a
    config bootstrapped with --print_config silently making the mask the actual secret.
  • A generic Protocol can now be implemented. Previously the TypeVar of the protocol and the type in the
    implementation could never be equal, so no class ever matched. A TypeVar on either side now matches any type, as
    static type checkers do.
  • Classes whose __new__ is wrapped by a decorator, e.g. to mark them deprecated or experimental, no longer end up with
    no parameters at all. The parameters are resolved from __init__ instead of from the wrapper.
  • A TypeVar used as the type itself, not only as the subtype of a type[...], is replaced by what it stands for: its
    PEP 696 default, its constraints or its bound. Previously the value was accepted without any validation.

Before submitting

  • Did you read the contributing guideline?
  • If you used a coding agent, did you fully understand and validate all generated code and ensure it follows the contributing guidelines?
  • Did you update the documentation? (readme and public docstrings)
  • Did you write unit tests such that there is 100% coverage on related code? (required for bug fixes and new features)
  • Did you verify that new and existing tests pass locally?
  • If this is a bug fix, did you verify that the tests fail without the code fix?
  • Did you make sure that all changes preserve backward compatibility?
  • Did you update the CHANGELOG including a pull request link? (not for typos, docs, test updates, or minor internal changes/refactors)

Comment thread jsonargparse_tests/test_subclasses.py Dismissed
Comment thread jsonargparse_tests/test_subclasses.py Dismissed
Comment thread jsonargparse_tests/test_subclasses.py Dismissed
Comment thread jsonargparse_tests/test_subclasses.py Dismissed
@mauvilsa
mauvilsa deployed to sonarcloud August 12, 2026 04:52 — with GitHub Actions Active
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7a860bf) to head (8512e39).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #953   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         8305      8390   +85     
=========================================
+ Hits          8305      8390   +85     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@sonarqubecloud

sonarqubecloud Bot commented Aug 12, 2026

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit a54f8e8 into main Aug 12, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the fix-dump-roundtrip-and-type-resolution branch August 12, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants