Skip to content

Support more typing constructs and make Hashable and Sized value types - #1007

Merged
mauvilsa merged 2 commits into
mainfrom
typing-constructs-hashable-sized-value-types
Oct 8, 2026
Merged

mauvilsa merged 2 commits into
mainfrom
typing-constructs-hashable-sized-value-types

Conversation

@mauvilsa

@mauvilsa mauvilsa commented Oct 7, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Support for more typing constructs that were not validated, Hashable and Sized changed from subclass types to value types, and fixes for annotations that crashed or were validated incorrectly.

Added:

  • Counter (values validated as int), ChainMap and Iterator types. An Iterator is kept as a list in the parsed config, so that dumping doesn't exhaust it, and becomes an iterator on instantiation.
  • Fields of dataclasses, attrs classes and pydantic dataclasses typed Final[X] or InitVar[X] are parsed as X, including InitVar[T] in a subscripted generic dataclass.

Changed:

  • Hashable and Sized are now value types instead of subclass types. A value is accepted if it is hashable or has a length, there is no --*.help option, and the config schema describes the accepted values. For Hashable, lists become tuples, since JSON and YAML have no tuples. For Sized, a dict with class_path is rejected, so that supporting subclass specs later would not be a breaking change. In ML frameworks Sized is used for the dataset of samplers, which can be given with link_arguments.

Fixed:

  • Variadic tuples, e.g. tuple[int, *Ts] or tuple[int, *tuple[str, ...]], and *args: *Ts, failed with The code should never reach here (python 3.10: Unable to add parameter) or were validated as having a fixed number of elements. Now they are unvalidated.
  • Signature parameters with an unhashable type, e.g. P.args of a ParamSpec, failed with unhashable type instead of being unvalidated.
  • A subclass spec with init_args whose class_path is the import path of an instance gave that instance, silently ignoring the init_args.
  • dict arguments with a Counter default parsed as an empty Counter.

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 refactor Improvements to the quality of the code labels Oct 7, 2026
@mauvilsa
mauvilsa deployed to sonarcloud October 7, 2026 21:05 — with GitHub Actions Active
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1007   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         9751      9798   +47     
=========================================
+ Hits          9751      9798   +47     

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

@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 3/5

[Medium risk] Extends type system support for parsing and validation.

Fix the lost ChainMap entries and unchecked bare Counter counts before merging.

Findings

  1. P1 Map overrides erase other entries ▶
  2. P1 Bare `Counter` skips count checks ▶
  3. P2 Schemas allow rejected values ▶

Summary

Adds support for Counter, ChainMap, and Iterator. Treats Hashable and Sized as value types, unwraps field annotations, and fixes several unsupported-annotation cases.

  • Dotted ChainMap overrides silently drop existing entries.
  • Bare Counter arguments still skip integer count checks.
  • The new Hashable and Sized schemas allow some values that parsing rejects.

Reviews (1) · Last reviewed commit: "Support more typing constructs and make ..." · Reviewed by Greptile

Comment thread jsonargparse/_typehints.py
Comment thread jsonargparse/_typehints.py Outdated
Comment thread jsonargparse/_completions_jsonschema.py Outdated
@mauvilsa
mauvilsa deployed to sonarcloud October 8, 2026 05:45 — with GitHub Actions Active
@sonarqubecloud

sonarqubecloud Bot commented Oct 8, 2026

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit f4b420a into main Oct 8, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the typing-constructs-hashable-sized-value-types branch October 8, 2026 05:52

This branch was successfully deployed

1 active deployment
sonarcloud — 9b3eec5d Deployed Oct 8, 2026 by mauvilsa via sonarcloud #955
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 refactor Improvements to the quality of the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant