Skip to content

Class types in containers: help option, known subclasses and set parsing; harden import path policy - #960

Merged
mauvilsa merged 5 commits into
mainfrom
improvements
Aug 24, 2026
Merged

Class types in containers: help option, known subclasses and set parsing; harden import path policy#960
mauvilsa merged 5 commits into
mainfrom
improvements

Conversation

@mauvilsa

Copy link
Copy Markdown
Owner

What does this PR do?

Follow-up to #959 with a few unrelated fixes on top. Four commits, each self-contained.

Class types nested in containers

  • --*.help is now available for class types nested in a tuple, set, frozenset or mapping (e.g. dict[str, SomeBaseClass]), not only in a list.
  • Known subclasses shown in the help now include subclasses of class types in any container, computed from a single get_class_types helper shared by help, extra help and shell completion.
  • Fixed: shell completion of a --*.help option gave wrong choices when the class type was nested in a container or optional, e.g. builtins.NoneType for Optional[list[SomeBaseClass]].
  • Fixed: set/frozenset of a class type failed to parse because subclass specs are not hashable. Such values are now kept as a list while parsing and become a set on instantiate.

Import path policy

  • jsonargparse itself is denied by default and rejected in import_path_allowlist, since a value naming it could call set_parsing_settings and change the policy that is checking it. ActionParser no longer goes through import_object for its own class.
  • Extended the default denylist: builtins.breakpoint/help/getattr/ setattr/delattr/vars/globals/exit/quit, cProfile, profile, doctest, unittest, _frozen_importlib*, pkg_resources, ensurepip, _sitebuiltins, resource, faulthandler, codecs.open, winreg, xml, antigravity.
  • Documented that type hints also bound what a config can reach, how objects without a defining path are attributed, and that the omegaconf parser modes bypass the denylist through OmegaConf resolvers (e.g. ${oc.env:...}) and should be avoided for untrusted configs.

Postponed annotations

  • Literal with arguments that are attributes of the class in whose body the method is defined now resolves. The class attribute values are only added as aliases for names inside a Literal subscript, so they can't shadow a global in a type position.

Misc

  • Removed the last pragma: no cover in _stubs_resolver.py, covered by a test.
  • The without-future-annotations tox env now uses {envtmpdir} instead of a fixed /tmp path, and sed -i.bak so it works on macOS.

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 Aug 24, 2026
@mauvilsa
mauvilsa deployed to sonarcloud August 24, 2026 05:11 — with GitHub Actions Active
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #960   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         8762      8784   +22     
=========================================
+ Hits          8762      8784   +22     

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

@sonarqubecloud

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit b4a91a2 into main Aug 24, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the improvements branch August 24, 2026 05:15
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