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
Make ModelWrapValidator protocols generic #7154
Conversation
Deploying with Cloudflare Pages
|
@@ -423,7 +423,7 @@ def __call__( # noqa: D102 | |||
ModelAfterValidator = Callable[[_ModelType, _core_schema.ValidationInfo], _ModelType] | |||
"""A `@model_validator` decorated function signature. This is used when `mode='after'`.""" | |||
|
|||
_AnyModelWrapValidator = Union[ModelWrapValidator, ModelWrapValidatorWithoutInfo] | |||
_AnyModelWrapValidator = Union[ModelWrapValidator[_ModelType], ModelWrapValidatorWithoutInfo[_ModelType]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this need to be parametrized later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my testing, adding the _ModelType
parameter to the overload return type on line 435 seems to give the right results for a correct and incorrect validator (and the after
overload does the same thing already):
) -> Callable[[_AnyModelWrapValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]:
That appears to be the only place where these types are used.
Unfortunately adding tests for these things is not easy. If the original example now works locally with mypy and pyright let's merge this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd agree with @adriangb.
LGTM.
Closes #7152
@samuelcolvin @adriangb is there any good way to add a test for this? Do we care enough to bother?