Skip to content

register_type replaces instead of failing, applies to subscripted types, and warns for callable defaults that can't be imported back - #966

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

register_type replaces instead of failing, applies to subscripted types, and warns for callable defaults that can't be imported back#966
mauvilsa merged 5 commits into
mainfrom
improvements

Conversation

@mauvilsa

Copy link
Copy Markdown
Owner

What does this PR do?

Replacing a registration. register_type failed when the type was already registered with a different serializer/deserializer. That made every new type registered by jsonargparse a breaking change for code that already registers it, e.g. a package registering os.PathLike before jsonargparse did. The new registration now replaces the previous one, and a debug log names the module of each, which is what you need to see when two packages register the same type. fail_already_registered=True keeps the old behavior. This also removes the _fail_already_registered global that jsonargparse used internally to exempt its own registrations from the check.

Subscripted types. A registered generic was ignored as soon as it was subscripted: os.PathLike worked but os.PathLike[str] did not. get_registered_type now falls back to the registration of the origin, so both spellings behave the same. Types are registered unsubscripted and the type arguments are not validated, since the deserializer gets the complete value.

Callable defaults. A Callable default whose import path contains <locals>, e.g. a closure, was dumped as that path, which looks valid but can't be imported back. The default is now kept as the object, so dump gives the usual Unable to serialize instance ... message together with a warning, instead of silently producing an unusable config.

Also: serialize_class_instance and the serialization branches for callables and class instances now go through a single serialize_as_import_path built on object_path_serializer, which is where the importability check already lived, and UntypedType.__init__ delegates to its parent instead of setting the attributes itself.

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 28, 2026
Comment thread jsonargparse_tests/test_typing.py Dismissed
@mauvilsa
mauvilsa deployed to sonarcloud August 28, 2026 14:37 — with GitHub Actions Active
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #966   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           28        28           
  Lines         9235      9250   +15     
=========================================
+ Hits          9235      9250   +15     

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

@sonarqubecloud

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit c9e025b into main Aug 28, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the improvements branch August 28, 2026 14:39
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.

2 participants