Skip to content

Add instantiators parameters - #995

Merged
mauvilsa merged 2 commits into
mainfrom
call-scoped-instantiators
Oct 1, 2026
Merged

mauvilsa merged 2 commits into
mainfrom
call-scoped-instantiators

Conversation

@mauvilsa

@mauvilsa mauvilsa commented Oct 1, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

  • New instantiators parameter of ArgumentParser.instantiate, auto_cli and FromConfigMixin.from_config, to use custom instantiators only within that call, including nested classes and partials for callables that return a class. This is recommended over the global add_instantiator, which affects other libraries that use jsonargparse.
  • The deprecation message of ArgumentParser.add_instantiator and the v5 migration guide now point to the new parameter.
  • Fixed custom instantiators with an applied_instantiation_links parameter missing links for classes nested in the init_args of another class, and for the partials that instantiate gives for callables that return a class.

These changes are also applied to the v4 branch via #994

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 1, 2026
@mauvilsa mauvilsa mentioned this pull request Oct 1, 2026
8 tasks done
Comment thread jsonargparse_tests/test_cli.py Fixed
@mauvilsa
mauvilsa deployed to sonarcloud October 1, 2026 06:42 — with GitHub Actions Active
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 3/5

[Medium risk] Adds optional instantiators parameter to class instantiation.

The PR is not ready to merge because auto_cli bypasses scoped instantiators for class components and fails with an existing-signature custom parser override.

Findings

  1. P1 Class instantiators are bypassed ▶
  2. P1 Custom parser overrides reject instantiators ▶

Summary

The PR adds call-scoped class instantiators to parser instantiation, auto_cli, and from_config, and carries instantiator and applied-link information into nested and deferred instantiation.

  • Adds validation and scoped-context propagation while retaining global instantiators as fallback.
  • Adds coverage and documentation for nested classes, links, subcommands, and deferred callables.
  • The auto_cli class-component and custom-parser paths need attention before the new option works consistently.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["auto_cli(..., instantiators=...)"] --> B["parser.instantiate(cfg)"]
  B --> C["Instantiate nested arguments"]
  C --> D["_run_component"]
  D --> E["Direct class construction"]
  D --> F["Function invocation"]
  E -. "Bypasses scoped instantiator" .-> G["Class component"]
Loading

Reviews (1) · Last reviewed commit: "Add instantiators parameters"

Comment thread jsonargparse/_cli.py Outdated
Comment thread jsonargparse/_cli.py Outdated
@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #995   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         9617      9647   +30     
=========================================
+ Hits          9617      9647   +30     

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

@mauvilsa
mauvilsa deployed to sonarcloud October 1, 2026 19:44 — with GitHub Actions Active
@sonarqubecloud

sonarqubecloud Bot commented Oct 1, 2026

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit 632b1dd into main Oct 1, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the call-scoped-instantiators branch October 1, 2026 19:47

This branch was successfully deployed

1 active deployment
sonarcloud — f35a8cd1 Deployed Oct 1, 2026 by mauvilsa via sonarcloud #931
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.

2 participants