Skip to content

Support string and recursive type aliases, sentinels and fix dataclass with custom init - #991

Merged
mauvilsa merged 2 commits into
mainfrom
fix-recursive-aliases-sentinels-dataclass-init
Sep 29, 2026
Merged

mauvilsa merged 2 commits into
mainfrom
fix-recursive-aliases-sentinels-dataclass-init

Conversation

@mauvilsa

Copy link
Copy Markdown
Owner

What does this PR do?

  • Support for TypeAliasType aliases whose value is a string, e.g. TypeAliasType("Json", "str | list[Json]"), evaluated in the module that defines the alias.
  • Support for PEP 661 sentinels as types, e.g. x: int | MISSING = MISSING, accepting only the sentinel given as its import path.
  • Fixed recursive type aliases, e.g. type Json = int | list[Json], failing with RecursionError, including in JSON schema generation.
  • Fixed sentinel defaults being shown in the help as <UnsetType object at 0x...>, and failing to serialize when the sentinel is not defined in the module of its class.
  • Fixed dataclasses with init=False and a hand-written __init__ getting parameter types from the fields instead of from __init__, so parameters that are not fields stayed unresolved and valid defaults were rejected.

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)

@mauvilsa mauvilsa added bug Something isn't working enhancement New feature or request labels Sep 29, 2026
@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #991   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         9505      9589   +84     
=========================================
+ Hits          9505      9589   +84     

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

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 3/5

[Medium risk] Extends type system support for aliases, sentinels, and dataclass init.

The PR should not merge until string aliases can recover from early resolution failures and JSON Schema generation terminates for recursive generic aliases.

Findings

  1. P1 Unresolved aliases stay unvalidated ▶
  2. P1 Changing type arguments defeat recursion ▶

Summary

This PR adds string-valued and recursive type-alias handling, PEP 661 sentinel support, sentinel-default serialization, and a correction for dataclasses with custom initializers.

  • String-alias resolution can retain an early resolution failure after the referenced name becomes available.
  • JSON Schema expansion does not terminate for recursive generic aliases whose arguments change at each level.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Alias type hint] --> B{String-valued?}
  B -- Yes --> C[Resolve in defining module]
  B -- No --> D[Get alias target]
  C --> D
  D --> E[Parse value or generate JSON Schema]
  E --> F{Recursive alias?}
  F -- Yes --> G[Build and reference definition]
  F -- No --> H[Expand target inline]
Loading

Reviews (1) · Last reviewed commit: "Support string and recursive type aliase..."

Comment thread jsonargparse/_optionals.py Outdated
Comment thread jsonargparse/_completions_jsonschema.py
@sonarqubecloud

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit ed88a11 into main Sep 29, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the fix-recursive-aliases-sentinels-dataclass-init branch September 29, 2026 06:35

This branch was successfully deployed

1 active deployment
sonarcloud — be4df4cc Deployed Sep 29, 2026 by mauvilsa via sonarcloud #917
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant