You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support more typing constructs and make Hashable and Sized value types - #1007
Support for more typing constructs that were not validated, Hashable and Sized changed from subclass types to value types, and fixes for annotations that crashed or were validated incorrectly.
Added:
Counter (values validated as int), ChainMap and Iterator types. An Iterator is kept as a list in the parsed config, so that dumping doesn't exhaust it, and becomes an iterator on instantiation.
Fields of dataclasses, attrs classes and pydantic dataclasses typed Final[X] or InitVar[X] are parsed as X, including InitVar[T] in a subscripted generic dataclass.
Changed:
Hashable and Sized are now value types instead of subclass types. A value is accepted if it is hashable or has a length, there is no --*.help option, and the config schema describes the accepted values. For Hashable, lists become tuples, since JSON and YAML have no tuples. For Sized, a dict with class_path is rejected, so that supporting subclass specs later would not be a breaking change. In ML frameworks Sized is used for the dataset of samplers, which can be given with link_arguments.
Fixed:
Variadic tuples, e.g. tuple[int, *Ts] or tuple[int, *tuple[str, ...]], and *args: *Ts, failed with The code should never reach here (python 3.10: Unable to add parameter) or were validated as having a fixed number of elements. Now they are unvalidated.
Signature parameters with an unhashable type, e.g. P.args of a ParamSpec, failed with unhashable type instead of being unvalidated.
A subclass spec with init_args whose class_path is the import path of an instance gave that instance, silently ignoring the init_args.
dict arguments with a Counter default parsed as an empty Counter.
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c044163) to head (9b3eec5).
✅ All tests successful. No failed tests found.
Adds support for Counter, ChainMap, and Iterator. Treats Hashable and Sized as value types, unwraps field annotations, and fixes several unsupported-annotation cases.
Dotted ChainMap overrides silently drop existing entries.
Bare Counter arguments still skip integer count checks.
The new Hashable and Sized schemas allow some values that parsing rejects.
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
bugSomething isn't workingenhancementNew feature or requestrefactorImprovements to the quality of the code
1 participant
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?
Support for more typing constructs that were not validated,
HashableandSizedchanged from subclass types to value types, and fixes for annotations that crashed or were validated incorrectly.Added:
Counter(values validated asint),ChainMapandIteratortypes. AnIteratoris kept as a list in the parsed config, so that dumping doesn't exhaust it, and becomes an iterator on instantiation.Final[X]orInitVar[X]are parsed asX, includingInitVar[T]in a subscripted generic dataclass.Changed:
HashableandSizedare now value types instead of subclass types. A value is accepted if it is hashable or has a length, there is no--*.helpoption, and the config schema describes the accepted values. ForHashable, lists become tuples, since JSON and YAML have no tuples. ForSized, a dict withclass_pathis rejected, so that supporting subclass specs later would not be a breaking change. In ML frameworksSizedis used for the dataset of samplers, which can be given withlink_arguments.Fixed:
tuple[int, *Ts]ortuple[int, *tuple[str, ...]], and*args: *Ts, failed withThe code should never reach here(python 3.10:Unable to add parameter) or were validated as having a fixed number of elements. Now they are unvalidated.P.argsof aParamSpec, failed withunhashable typeinstead of being unvalidated.init_argswhoseclass_pathis the import path of an instance gave that instance, silently ignoring theinit_args.dictarguments with aCounterdefault parsed as an emptyCounter.Before submitting