Skip to content

mypy plugin working incorrectly for exported v1 module #6898

@JaimeLennox

Description

@JaimeLennox

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

Metadata

Metadata

Assignees

Labels

bug V2Bug related to Pydantic V2pendingIs unconfirmed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy