-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Feature request
Similar to the issue that #2721 solves, VS Code can't auto complete models constructor parameters when using pydantic.dataclasses.dataclass.
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.9.0
pydantic compiled: True
install path: /tmp/hello-world/.venv/lib/python3.10/site-packages/pydantic
python version: 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0]
platform: Linux-5.10.105-1-MANJARO-x86_64-with-glibc2.35
optional deps. installed: ['typing-extensions']
Example Code:
import pydantic
from pydantic.dataclasses import dataclass
@dataclass
class Hello:
n: int
s: str
hello = Hello(n=1, s="a")
hello.nVS Code:
pydantic-bug-2022-04-24_09.29.26.mp4
Workaround:
You can import python pure dataclass instead of pydantic's dataclass when type checking, as stated by @JosXa here:
from pydantic.dataclasses import dataclass
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from dataclasses import dataclass
else:
from pydantic.dataclasses import dataclass as dataclasssorig