Skip to content

mypy complains about pre=True root validators #984

@bochecha

Description

@bochecha

Bug

Please complete:

  • OS: Ubuntu 19.04
  • Python version import sys; print(sys.version): 3.7.3
  • Pydantic version import pydantic; print(pydantic.VERSION): 1.0

With the code found in the root validators documentation:

from pydantic import BaseModel, root_validator


class UserModel(BaseModel):
    username: str
    password1: str
    password2: str

    @root_validator(pre=True)
    def check_card_number_omitted(cls, values):  # type: ignore
        assert 'card_number' not in values, 'card_number should not be included'
        return values

Mypy has the following to say:

9: error: "classmethod" not callable

The following change pleases mypy, but of course that changes the semantics:

-    @root_validator(pre=True)
+    @root_validator

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