You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 appears to have been introduced by using @dataclass_transform on the metaclass, and the reason that it works in 1.10.2 is because that version used the keyword argument field_descriptors instead of the correct field_specifiers.
I'm not sure how involved it will be to fix this properly while retaining the @dataclass_transform behavior; the good news is that in v2 this shouldn't be an issue because we no longer set an implicit default for Optional/Any fields.
Does anyone know why the keyword argument was field_descriptors before? Was that just a typo?
Seems there was some logic issues in the plugin that meant it wouldn't work correctly if you set a Field as the default but didn't specify default or default_factory. The dataclass_transform thing was just hiding the issue. I've got a fix coming shortly.
Initial Checks
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
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
Python, Pydantic & OS Version
Affected Components
.dict()
and.json()
construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: