Pydantic: Support for types annotated with Field(default_factory)
#11539
Joshua Noeske (PatrickJosh)
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi, when using Pydantic, I can annotate the type of an attribute with
Field(default_factory)to provide a function for setting default values if the caller did not supply a value for that attribute. See the following example:Pyright produces an error on calling
Test()with no arguments although the specifieddefault_factoryautomatically provides a default value.In the Pydantic docs, it is actually noted that static type checkers do not support this pattern, see the annotated pattern.
Since I've not found any discussions on this, I'd like to ask, might it be possible to add support for this pattern to Pyright or is there anything that prevents this from being added?
All reactions