TypedDict help+completions, Any/Unvalidated dumping, scoped postponed annotations, abstract dataclass-like types and pydantic/attrs aliases - #956
Merged
Conversation
…ject abstract class paths
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #956 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 27 27
Lines 8464 8600 +136
==========================================
+ Hits 8464 8600 +136 ☔ 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?
Five independent improvements, one per commit:
TypedDicthelp and completions — arguments typed as aTypedDictnow have a--*.helpoption listing the accepted keys, their types and their descriptions;add_class_argumentsaccepts aTypedDict, adding one argument per key; docstring descriptions of keys are shown for**kwargs: Unpack[SomeTypedDict]parameters; andshtabcompletion scripts include the keys and the values they accept, no longer showingNotRequired[...]as the expected type.Dumping of
AnyandUnvalidatedvalues —dump, and thus--print_config, no longer fails when the value is of a type the config format can't represent, e.g. a class instance, or asetin json. A type is now derived from the value and used to serialize it, class instances become an import path or a not-serializable message, and a warning is raised when the dumped value does not round-trip.Postponed annotations of methods — names defined in the body of a class are now resolved for its methods' annotations, by using the class namespace as locals.
Abstract dataclass-like types — these now have subclass support enabled by default, since previously they were unusable: the
class_pathof an implementation was rejected and giving the fields directly failed oninstantiate. Additionally, theclass_pathof an abstract class is now rejected at parse time withExpected an instantiatable class, but ... is abstract, instead of failing later oninstantiate. This also applies when theclass_pathis implicit or the class is given by name.pydantic and attrs field aliases — pydantic's
aliasandvalidation_aliasand attrs'aliasare now accepted as option and config keys, so a parser accepts the same names as the class itself. This fixes values being silently discarded for pydantic models withoutpopulate_by_nameand attrs fields with an explicit alias or a private attribute failing to instantiate.Before submitting