Closed vadim-su closed 1 year ago
Pylance has no special knowledge of pydantic's behaviors. Instead we support pydantic's dataclasses via their use of dataclass_transform
. PEP 681 specifies that the standardized parameters (like default
) that are passed to field specifiers (the term used for functions like pydantic's Field
) must be keyword-only. Field.default
is a positional-or-keyword parameter and you are currently passing your default values as positional arguments.
If you explicitly provide the parameter name (default=
), Pylance will work as you expect. Its current behavior is by design.
from pydantic import BaseModel, Field
class Image(BaseModel):
url: str | None = Field(default=None, title='The URL of the image')
name: str
size: int = Field(default=..., gt=0, description='The size of the image in bytes')
img = Image(name='example')
Environment data
3-bullseye
mcr.microsoft.com/vscode/devcontainers/python
Code Snippet