Skip to content

Nested Model model definition raises "Type variable cannot be used as an expression" in mypy with plugin #1770

@selimb

Description

@selimb

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.6.1
            pydantic compiled: False
                 install path: D:\sand\pydantic-nested\.venv\Lib\site-packages\pydantic
               python version: 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 18 2019, 23:46:00) [MSC v.1916 32 bit (Intel)]
                     platform: Windows-10-10.0.19559-SP0
     optional deps. installed: ['typing-extensions']

Additionally, I'm using mypy==0.782 (latest as of today).

# bug.py
import pydantic

class Job(pydantic.BaseModel):
    class Model(pydantic.BaseModel):
        id: str
        md5: str

    model: Model

Job.Model  # error on this line
# setup.cfg
[mypy]
plugins = pydantic.mypy
$ mypy bug.py 
bug.py:10: error: Type variable "Article.Model" cannot be used as an expression
Found 1 error in 1 file (checked 1 source file)

If I rename Model to anything else, the mypy error disappears.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions