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
Since pydantic 1.10.2, it fails to parse a builtin dataclass dataclass.field(init=False) if it has at least one method.
Similarly to #4498, the cause seems this change in #4484.
Example Code
importdataclassesimportpydantic@dataclasses.dataclassclassOk:
a: intb: str="b"c: float=dataclasses.field(init=False)
def__post_init__(self):
self.c=float(self.a)
@dataclasses.dataclassclassNotOkSince1_10_2:
a: intb: str="b"c: float=dataclasses.field(init=False)
def__post_init__(self):
self.c=float(self.a)
@pydantic.validator("b")defcheck_b(cls, v):
ifnotv:
raiseValueError("b should not be empty")
returnv# ... or with a non-validator method# def foo(self):# print("foo")print(pydantic.parse_obj_as(Ok, {"a": 3})) # Ok(a=3, b='b', c=3.0)print(pydantic.parse_obj_as(NotOkSince1_10_2, {"a": 3})) # TypeError: non-default argument 'c' follows default argument
Initial Checks
Description
Since pydantic 1.10.2, it fails to parse a builtin dataclass
dataclass.field(init=False)
if it has at least one method.Similarly to #4498, the cause seems this change in #4484.
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: