Skip to content
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

fix: make function validator types positional-only #8479

Merged
merged 1 commit into from Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 28 additions & 18 deletions pydantic/functional_validators.py
Expand Up @@ -216,20 +216,21 @@ def __get_pydantic_core_schema__(self, source_type: Any, handler: _GetCoreSchema
if TYPE_CHECKING:

class _OnlyValueValidatorClsMethod(Protocol):
def __call__(self, __cls: Any, __value: Any) -> Any:
def __call__(self, cls: Any, value: Any, /) -> Any:
...

class _V2ValidatorClsMethod(Protocol):
def __call__(self, __cls: Any, __input_value: Any, __info: _core_schema.ValidationInfo) -> Any:
def __call__(self, cls: Any, value: Any, info: _core_schema.ValidationInfo, /) -> Any:
...

class _V2WrapValidatorClsMethod(Protocol):
def __call__(
self,
__cls: Any,
__input_value: Any,
__validator: _core_schema.ValidatorFunctionWrapHandler,
__info: _core_schema.ValidationInfo,
cls: Any,
value: Any,
handler: _core_schema.ValidatorFunctionWrapHandler,
info: _core_schema.ValidationInfo,
/,
) -> Any:
...

Expand Down Expand Up @@ -379,7 +380,10 @@ class ModelWrapValidatorHandler(_core_schema.ValidatorFunctionWrapHandler, Proto
"""@model_validator decorated function handler argument type. This is used when `mode='wrap'`."""

def __call__( # noqa: D102
self, input_value: Any, outer_location: str | int | None = None
self,
value: Any,
outer_location: str | int | None = None,
/,
) -> _ModelTypeCo: # pragma: no cover
...

Expand All @@ -395,8 +399,9 @@ def __call__( # noqa: D102
# this can be a dict, a model instance
# or anything else that gets passed to validate_python
# thus validators _must_ handle all cases
__value: Any,
__handler: ModelWrapValidatorHandler[_ModelType],
value: Any,
handler: ModelWrapValidatorHandler[_ModelType],
/,
) -> _ModelType:
...

Expand All @@ -410,9 +415,10 @@ def __call__( # noqa: D102
# this can be a dict, a model instance
# or anything else that gets passed to validate_python
# thus validators _must_ handle all cases
__value: Any,
__handler: ModelWrapValidatorHandler[_ModelType],
__info: _core_schema.ValidationInfo,
value: Any,
handler: ModelWrapValidatorHandler[_ModelType],
info: _core_schema.ValidationInfo,
/,
) -> _ModelType:
...

Expand All @@ -427,7 +433,8 @@ def __call__( # noqa: D102
# this can be a dict, a model instance
# or anything else that gets passed to validate_python
# thus validators _must_ handle all cases
__value: Any,
value: Any,
/,
) -> Any:
...

Expand All @@ -443,7 +450,8 @@ def __call__( # noqa: D102
# this can be a dict, a model instance
# or anything else that gets passed to validate_python
# thus validators _must_ handle all cases
__value: Any,
value: Any,
/,
) -> Any:
...

Expand All @@ -456,8 +464,9 @@ def __call__( # noqa: D102
# this can be a dict, a model instance
# or anything else that gets passed to validate_python
# thus validators _must_ handle all cases
__value: Any,
__info: _core_schema.ValidationInfo,
value: Any,
info: _core_schema.ValidationInfo,
/,
) -> Any:
...

Expand All @@ -471,8 +480,9 @@ def __call__( # noqa: D102
# this can be a dict, a model instance
# or anything else that gets passed to validate_python
# thus validators _must_ handle all cases
__value: Any,
__info: _core_schema.ValidationInfo,
value: Any,
info: _core_schema.ValidationInfo,
/,
) -> Any:
...

Expand Down