Skip to content

Commit a4e9dd4

Browse files
committed
fix: return return Any in pydantic type stub
1 parent 13e1944 commit a4e9dd4

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

src/pydantic.pyi

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,32 @@
1111
"""Stub file containing a skeleton of the public interface of `pydantic` library"""
1212

1313
from abc import ABCMeta
14-
from typing import Any, Literal, Generator, Mapping, Set, Tuple, TypeAlias, Union
15-
from typing_extensions import Annotated, Self
14+
from typing import (
15+
Any,
16+
Callable,
17+
Literal,
18+
Generator,
19+
Mapping,
20+
Protocol,
21+
Set,
22+
Tuple,
23+
TypeAlias,
24+
TypeVar,
25+
Union,
26+
)
27+
from typing_extensions import Annotated, Generic, Self
28+
29+
_ModelType = TypeVar("_ModelType")
30+
IncEx: TypeAlias = Union[
31+
Set[int], Set[str], Mapping[int, Union["IncEx", bool]], Mapping[str, Union["IncEx", bool]]
32+
]
33+
ModelAfterValidator = Callable[[_ModelType, ValidationInfo], _ModelType]
34+
ModelAfterValidatorWithoutInfo = Callable[[_ModelType], _ModelType]
35+
StrictBool = Annotated[bool, ...]
36+
StrictInt = Annotated[int, ...]
37+
StrictStr = Annotated[str, ...]
38+
ReturnType = TypeVar("ReturnType")
39+
TupleGenerator: TypeAlias = Generator[Tuple[str, Any], None, None]
1640

1741
class BaseModel(metaclass=ABCMeta):
1842
def __iter__(self) -> TupleGenerator: ...
@@ -40,15 +64,18 @@ class BaseModel(metaclass=ABCMeta):
4064
context: Any | None = None,
4165
) -> Self: ...
4266

43-
IncEx: TypeAlias = Union[
44-
Set[int], Set[str], Mapping[int, Union["IncEx", bool]], Mapping[str, Union["IncEx", bool]]
45-
]
46-
StrictBool = Annotated[bool, ...]
47-
StrictInt = Annotated[int, ...]
48-
StrictStr = Annotated[str, ...]
49-
TupleGenerator: TypeAlias = Generator[Tuple[str, Any], None, None]
50-
67+
class ModelValidatorDecoratorInfo(metaclass=ABCMeta): ...
68+
class PydanticDescriptorProxy(Generic[ReturnType], metaclass=ABCMeta): ...
5169
class ValidationError(ValueError, metaclass=ABCMeta): ...
70+
class ValidationInfo(Protocol, metaclass=ABCMeta): ...
71+
72+
_AnyModelAfterValidator = Union[
73+
ModelAfterValidator[_ModelType], ModelAfterValidatorWithoutInfo[_ModelType]
74+
]
5275

5376
def create_model(model_name: str) -> type[BaseModel]: ...
54-
def model_validator(*, mode: Literal["wrap", "before", "after"]) -> Any: ...
77+
def model_validator(
78+
*, mode: Literal["after"]
79+
) -> Callable[
80+
[_AnyModelAfterValidator[_ModelType]], PydanticDescriptorProxy[ModelValidatorDecoratorInfo]
81+
]: ...

0 commit comments

Comments
 (0)