mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
02a076d14f
The mypy plugin would previously incorrectly determine that a field was not required in a few scenarios where the field really is required. This specifically affected cases when the `Field()` function is used, where the plugin assumed that the first argument would always be `default`. This changes the code to examine each argument more closely, and it now properly handles several more scenarios where the default is explicitly named or when the default_factory named argument is used.
18 lines
462 B
Python
18 lines
462 B
Python
from pydantic import BaseModel, Field
|
|
|
|
|
|
class Model(BaseModel):
|
|
# Required
|
|
undefined_default_no_args: int = Field()
|
|
undefined_default: int = Field(description='my desc')
|
|
positional_ellipsis_default: int = Field(...)
|
|
named_ellipsis_default: int = Field(default=...)
|
|
|
|
# Not required
|
|
positional_default: int = Field(1)
|
|
named_default: int = Field(default=2)
|
|
named_default_factory: int = Field(default_factory=lambda: 3)
|
|
|
|
|
|
Model()
|