-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Initial Checks
- I have searched GitHub for a duplicate issue and I'm sure this is something new
- I have searched Google & StackOverflow for a solution and couldn't find anything
- I have read and followed the docs and still think this is a bug
- I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)
Description
pydantic version 1.10.6 + mypy 1.1.1 + mypy plugin causes error with previously ok code.
Note: mypy plugin is irrelevant, and does not affect the output in this usecase
Using Field with a description on an optional Field, without an explicit default=None, used to work
$ mypy sample.py
sample.py:10: error: Missing named argument "bar" for "Sample" [call-arg]
Found 1 error in 1 file (checked 1 source file)
Error started happening with pydantic 1.10.4, version 1.10.2 does not have this issue
versions >1.10.2 now require the explicit default=None on Optional fields.
This seems like a bug, if not please advise.
Example Code
from typing import Optional
from pydantic import BaseModel, Field
class Sample(BaseModel):
foo: str
bar: Optional[str] = Field(description="optional")
Sample(foo="hello world")Python, Pydantic & OS Version
pydantic version: 1.10.6
pydantic compiled: True
install path: /home/hatem/projects/inventory_service/venv/lib/python3.8/site-packages/pydantic
python version: 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
platform: Linux-5.11.0-37-generic-x86_64-with-glibc2.29
optional deps. installed: ['dotenv', 'typing-extensions']
Affected Components
- Compatibility between releases
- Data validation/parsing
- Data serialization -
.dict()and.json() - JSON Schema
- Dataclasses
- Model Config
- Field Types - adding or changing a particular data type
- Function validation decorator
- Generic Models
- Other Model behaviour -
construct(), pickling, private attributes, ORM mode - Plugins and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.
yuvalshi0