-
Notifications
You must be signed in to change notification settings - Fork 280
Make ValidationInfo
generic for context
#1686
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
from re import Pattern | ||
from typing import TYPE_CHECKING, Any, Callable, Literal, Union | ||
|
||
from typing_extensions import deprecated | ||
from typing_extensions import TypeVar, deprecated | ||
|
||
if sys.version_info < (3, 12): | ||
from typing_extensions import TypedDict | ||
|
@@ -163,13 +163,16 @@ class FieldSerializationInfo(SerializationInfo, Protocol): | |
def field_name(self) -> str: ... | ||
|
||
|
||
class ValidationInfo(Protocol): | ||
ContextT = TypeVar('ContextT', covariant=True, default='Any | None') | ||
|
||
|
||
class ValidationInfo(Protocol[ContextT]): | ||
Comment on lines
+166
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add some mypy tests for this / maybe also the covariance? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do so in Pydantic after updating the core version. The covariance is required because it is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess maybe it is defined this way so that it cannot be instantiated (at least for static type checkers, at runtime it would still be possible)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean move this EDIT see below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah actually it's not exported by the library, so having it in I guess this is why it's defined as a protocol here, the Rust type then satisfies the protocol without needing to actually be related to it in the hierarchy. |
||
""" | ||
Argument passed to validation functions. | ||
""" | ||
|
||
@property | ||
def context(self) -> Any | None: | ||
def context(self) -> ContextT: | ||
"""Current validation context.""" | ||
... | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Do we need to call this out in the changelog?
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.
Pydantic already requires 4.12, so I don't think so.