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

Make ModelWrapValidator protocols generic #7154

Merged
merged 1 commit into from Aug 22, 2023

Conversation

dmontagu
Copy link
Contributor

Closes #7152

@samuelcolvin @adriangb is there any good way to add a test for this? Do we care enough to bother?

@cloudflare-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ed1fcd2
Status: ✅  Deploy successful!
Preview URL: https://eea9d29c.pydantic-docs2.pages.dev
Branch Preview URL: https://dmontagu-model-wrap-validato.pydantic-docs2.pages.dev

View logs

@@ -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]]
Copy link
Member

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?

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.

@adriangb
Copy link
Member

Unfortunately adding tests for these things is not easy. If the original example now works locally with mypy and pyright let's merge this.

Copy link
Member

@samuelcolvin samuelcolvin left a 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.

@adriangb adriangb merged commit 1bb2227 into main Aug 22, 2023
50 checks passed
@adriangb adriangb deleted the dmontagu/model-wrap-validator-generic-protocol branch August 22, 2023 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pyright type error with @model_validator(mode="wrap")
4 participants