Skip to content

Add instantiators parameters - #994

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

mauvilsa merged 2 commits into
v4from
call-scoped-instantiators-v4

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 main branch via #995

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 deployed to sonarcloud October 1, 2026 05:28 — with GitHub Actions Active
@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 (4b852f1) to head (50b8b0a).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##                v4      #994   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           28        28           
  Lines         9430      9457   +27     
=========================================
+ Hits          9430      9457   +27     

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

@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 methods.

This PR is not yet safe to merge because deferred callables can receive another configuration’s link values and existing subparser overrides can fail.

Findings

  1. P1 Deferred callables use later link values ▶
  2. P1 Existing subparser overrides fail ▶

Summary

Adds call-scoped custom instantiators to parser instantiation, auto_cli, and from_config, and propagates instantiation-link information into nested and deferred class construction.

  • Updates documentation, migration guidance, and tests for the new parameter.
  • Two compatibility and deferred-value defects need correction.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["instantiate cfg1"] --> B["deferred callable captures link actions"]
  B --> C["instantiate cfg2 overwrites action values"]
  C --> D["invoke cfg1 callable"]
  D --> E["instantiator reads cfg2 link values"]
Loading

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

Comment thread jsonargparse/_instantiation.py Outdated
Comment thread jsonargparse/_instantiation.py Outdated
@mauvilsa
mauvilsa deployed to sonarcloud October 1, 2026 06:26 — with GitHub Actions Active
@sonarqubecloud

sonarqubecloud Bot commented Oct 1, 2026

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit bc5d73c into v4 Oct 1, 2026
30 checks passed
@mauvilsa
mauvilsa deleted the call-scoped-instantiators-v4 branch October 1, 2026 06:29

This branch was successfully deployed

1 active deployment
sonarcloud — 50b8b0a0 Deployed Oct 1, 2026 by mauvilsa via sonarcloud #926
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