Skip to content

Commit f02fa0e

Browse files
committed
Make ValidationInfo generic for context
1 parent d7bfe90 commit f02fa0e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

python/pydantic_core/core_schema.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from re import Pattern
1414
from typing import TYPE_CHECKING, Any, Callable, Literal, Union
1515

16-
from typing_extensions import deprecated
16+
from typing_extensions import TypeVar, deprecated
1717

1818
if sys.version_info < (3, 12):
1919
from typing_extensions import TypedDict
@@ -163,13 +163,16 @@ class FieldSerializationInfo(SerializationInfo, Protocol):
163163
def field_name(self) -> str: ...
164164

165165

166-
class ValidationInfo(Protocol):
166+
ContextT = TypeVar('ContextT', covariant=True, default='Any | None')
167+
168+
169+
class ValidationInfo(Protocol[ContextT]):
167170
"""
168171
Argument passed to validation functions.
169172
"""
170173

171174
@property
172-
def context(self) -> Any | None:
175+
def context(self) -> ContextT:
173176
"""Current validation context."""
174177
...
175178

0 commit comments

Comments
 (0)