Skip to content

New Untyped type, fail_untyped='all' and debug logs for adjusted signature parameters - #965

Merged
mauvilsa merged 1 commit into
mainfrom
untyped-type
Aug 28, 2026
Merged

New Untyped type, fail_untyped='all' and debug logs for adjusted signature parameters#965
mauvilsa merged 1 commit into
mainfrom
untyped-type

Conversation

@mauvilsa

@mauvilsa mauvilsa commented Aug 28, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

fail_untyped=True only fails for required parameters without a type annotation. One that has a default is silently added as Union[<type of the default>, Any], indistinguishable in the help from a parameter genuinely annotated as Any, and there was no way to require that everything the parser exposes is typed.

New Untyped type. Parameters without a type annotation are now added as Untyped instead of Any, so the help says what is actually the case:

--a2 A2     (type: Union[int, Untyped], default: 3)

It is a subclass of UnvalidatedType, thus accepts any value without validation as Any did, and union ordering, dump, --print_config and the JSON schema treat it identically.

Uniform type. With fail_untyped=False a parameter with a default used to get plain Any, i.e. the stricter setting was the one inferring from the default. Both now give Union[<type of the default>, Untyped], leaving one rule: an untyped parameter gets Untyped when required and Union[<type of the default>, Untyped] when it has a default, and fail_untyped only decides whether to raise instead.

fail_untyped="all". Raises for every untyped parameter, not only the required ones, and propagates into subclass types. True and False keep their meaning and are not deprecated. "all" is only viable for code you own, since one untyped parameter of a dependency makes its signature impossible to add, so the default is unchanged.

Debug logs for five previously silent cases where the type or the requiredness differs from the signature: no type annotation, a parameter skipped because its name starts with _, a None default widening the type to Optional, a NotRequired parameter without a default, and a link target. Nothing is logged for the two behaviors that v5 removes.

Also: UnvalidatedType.__eq__ and __hash__ now include the class, and the "Unvalidated types" section and signature notes were shortened while documenting the above.

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?
  • [n/a] 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)

@mauvilsa mauvilsa added enhancement New feature or request refactor Improvements to the quality of the code labels Aug 28, 2026
Comment thread jsonargparse/_typehints.py Dismissed
Comment thread jsonargparse/_typehints.py Dismissed
@mauvilsa
mauvilsa deployed to sonarcloud August 28, 2026 08:00 — with GitHub Actions Active
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #965   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           28        28           
  Lines         9209      9235   +26     
=========================================
+ Hits          9209      9235   +26     

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

@sonarqubecloud

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit 2b892ef into main Aug 28, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the untyped-type branch August 28, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request refactor Improvements to the quality of the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants