-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X
Description
Checks
- I added a descriptive title to this issue
- I have searched (google, github) for similar issues and couldn't find anything
- I have read and followed the docs and still think this is a bug
Bug
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.7
pydantic compiled: True
install path: /Users/kittipat/pydantic_test/lib/python3.7/site-packages/pydantic
python version: 3.7.9 (default, Sep 30 2020, 11:16:22) [Clang 11.0.0 (clang-1100.0.33.17)]
platform: Darwin-19.6.0-x86_64-i386-64bit
optional deps. installed: []
Prior to version 1.7, it was possible to subclass from stdlib dataclass. In version 1.7, doing so will result in error. Here is a minimal repro.
#!/usr/bin/env python3
from dataclasses import field, dataclass as vanilla_dataclass
from pydantic.dataclasses import dataclass
@vanilla_dataclass
class X:
y: int = 0
@dataclass
class A(X):
x: int = 1
@dataclass
class B:
a: A = field(default_factory=lambda: A(x=2, y=3))
def main():
print(B(**{"a": {"x": "4", "y": "5"}}))
if __name__ == "__main__":
main()Running with version 1.6
B(a=A(y=5, x=4))
Running with version 1.7
Traceback (most recent call last):
File "dataclass.py", line 15, in <module>
@dataclass
File "pydantic/dataclasses.py", line 214, in pydantic.dataclasses.dataclass
# name and type are filled in after the fact, not in __init__.
File "pydantic/dataclasses.py", line 209, in pydantic.dataclasses.dataclass.wrap
File "pydantic/dataclasses.py", line 138, in pydantic.dataclasses._process_class
# +-------+-------+-------+--------+--------+
File "dataclass.py", line 17, in <lambda>
a: A = field(default_factory=lambda: A(x=2, y=3))
TypeError: __init__() got an unexpected keyword argument 'x'
aloosley and larsthorup
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X