New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mypy type issues with model_validator() #6693
Comments
I would add
But it can be Some of these other ones are questionable, e.g. The most correct signatures to use are |
Closing since we don't plan on making any changes (aside from maybe tweaking the docs) |
Thank you for clarifying the intended API for before. With the current state of the documentation, it wasn't clear that As for after, from pydantic import model_validator, BaseModel, ConfigDict
class Foo(BaseModel):
model_config = ConfigDict(
extra="forbid", str_min_length=1, frozen=True, strict=True
)
a: int = 1
b: bool
@model_validator(mode="after")
def _after_annotated_return_self(self) -> "Foo":
print("\n_after_annotated_return_self()")
return self
foo = Foo(a=2, b=True)
There is also the "Cannot infer function type argument" error. I saw python/mypy#15620. Maybe this means that the |
#6709 captures the issue I posted about above as I am also using the pydantic mypy plugin. |
Initial Checks
Description
I am trying to port a project to pydantic v2 that uses model validators. I am seeing a number of errors for
mypy
that make me not sure about what is the intended API versus what might be potential bugs in the type annotations exposed tomypy
. (The validators documentation page, still has a warning that the page still needs to be updated, but seems to have had some updates. If these docs were in a known state, I might have a better idea of where the error might be.)Based on the example code, it seems like:
@classmethod
). Returningself
ordata
, respectively, does not cause any runtime errors.Foo
: actual type isdict
. NOmypy
error ❌mypy
✔️self
type isdict
.mypy
error that function signature is not correct and return type is wrong ❓Foo
: actual type matches.mypy
error that function signature is not correct ❌Foo
.mypy
error that function signature is not correct ✔️self
type isFoo
.mypy
error that function signature is not correct and return type is wrong ❓mypy output:
pyproject.toml:
Example Code
Python, Pydantic & OS Version
Selected Assignee: @adriangb
The text was updated successfully, but these errors were encountered: