Fix dump round-tripping, generic protocols, TypeVar types and extend subclass spec validation - #953
Merged
Merged
Conversation
…, wrapped __new__ and TypeVar types
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #953 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 8305 8390 +85
=========================================
+ Hits 8305 8390 +85 ☔ View full report in Codecov by Harness. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What does this PR do?
Two related groups of changes.
Subclass spec validation beyond
Any— thevalidate_subclass_spec_in_anysetting now also applies toUnvalidated<...>and to dicts that don't validate their values, e.g.dict[str, Any]. For dicts the spec is onlyvalidated and the value kept as a dict, which matters for unions such as
Union[SomeClass, dict[str, Any]], where aspec rejected by the class member would otherwise be silently swallowed by the dict member.
Fixes around dumping and type resolution:
dumpand--print_confignow round-trip values given as an import path to an instance. Previously the dump had a"not serializable" message unless the instance happened to be defined in the module of its class; now the import path
the value was resolved from is remembered and dumped back.
**********as aSecretStr(both jsonargparse's and pydantic's) now fails, instead of aconfig bootstrapped with
--print_configsilently making the mask the actual secret.Protocolcan now be implemented. Previously theTypeVarof the protocol and the type in theimplementation could never be equal, so no class ever matched. A
TypeVaron either side now matches any type, asstatic type checkers do.
__new__is wrapped by a decorator, e.g. to mark them deprecated or experimental, no longer end up withno parameters at all. The parameters are resolved from
__init__instead of from the wrapper.TypeVarused as the type itself, not only as the subtype of atype[...], is replaced by what it stands for: itsPEP 696
default, its constraints or its bound. Previously the value was accepted without any validation.Before submitting