-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Initial Checks
- I confirm that I'm using Pydantic V2
Description
Hello! We're beginning our migration to pydantic v2, and as a first step we thought we'd simply upgrade the version and use the exported v1 module simply by changing import pydantic
to import pydantic.v1
in our imports.
This works fine for the most part, but the mypy plugin doesn't seem to work anymore (note that we switched our mypy configuration to use plugins = "pydantic.v1.mypy"
).
This is most obvious with the v1 BaseSettings
class, where we load atrributes from a .env
file.
For the example code below, running with pydantic v1 produces no errors, but pydantic v2 with the v1 mypy plugin shows:
test.py:11: error: Missing named argument "foo" for "Settings" [call-arg]
I think this is probably because in the v1 mypy plugin, the fullname constants aren't using the v1 module?
E.g.
BASEMODEL_FULLNAME = 'pydantic.main.BaseModel'
should probably be
BASEMODEL_FULLNAME = 'pydantic.v1.main.BaseModel'
?
Example Code
from pydantic.v1 import BaseSettings
class Settings(BaseSettings):
foo: str
class Config:
env_file = ".env"
settings = Settings()
Python, Pydantic & OS Version
pydantic version: 2.0.3
pydantic-core version: 2.3.0 release build profile
install path: /Users/test/.virtualenvs/venv/lib/python3.11/site-packages/pydantic
python version: 3.11.0 (main, Nov 1 2022, 09:15:56) [Clang 13.1.6 (clang-1316.0.21.2.5)]
platform: macOS-13.4.1-arm64-arm-64bit
optional deps. installed: ['email-validator', 'typing-extensions']
Selected Assignee: @dmontagu