Skip to content

Type stubs: Incorrect return type on validate_assignment #947

Open
@hassec

Description

@hassec

Is it possible that the below type stub is incorrect?

def validate_assignment(
self,
obj: Any,
field_name: str,
field_value: Any,
*,
strict: bool | None = None,
from_attributes: bool | None = None,
context: 'dict[str, Any] | None' = None,
) -> dict[str, Any] | tuple[dict[str, Any], dict[str, Any] | None, set[str]]:

In the below example the returned value seems to be a of type A.

from pydantic import BaseModel

class A(BaseModel, validate_assignment=True):
    i: int

a = A(i=1)
x = a.__pydantic_validator__.validate_assignment(a, "i", 3)
print(type(x))  # <class '__main__.A'>
print(x is a)  # True

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions