13
13
from re import Pattern
14
14
from typing import TYPE_CHECKING , Any , Callable , Literal , Union
15
15
16
- from typing_extensions import deprecated
16
+ from typing_extensions import TypeVar , deprecated
17
17
18
18
if sys .version_info < (3 , 12 ):
19
19
from typing_extensions import TypedDict
@@ -118,17 +118,20 @@ class CoreConfig(TypedDict, total=False):
118
118
119
119
IncExCall : TypeAlias = 'set[int | str] | dict[int | str, IncExCall] | None'
120
120
121
+ ContextT = TypeVar ('ContextT' , covariant = True , default = 'Any | None' )
121
122
122
- class SerializationInfo (Protocol ):
123
+
124
+ class SerializationInfo (Protocol [ContextT ]):
123
125
@property
124
126
def include (self ) -> IncExCall : ...
125
127
126
128
@property
127
129
def exclude (self ) -> IncExCall : ...
128
130
129
131
@property
130
- def context (self ) -> Any | None :
132
+ def context (self ) -> ContextT :
131
133
"""Current serialization context."""
134
+ ...
132
135
133
136
@property
134
137
def mode (self ) -> str : ...
@@ -163,13 +166,13 @@ class FieldSerializationInfo(SerializationInfo, Protocol):
163
166
def field_name (self ) -> str : ...
164
167
165
168
166
- class ValidationInfo (Protocol ):
169
+ class ValidationInfo (Protocol [ ContextT ] ):
167
170
"""
168
171
Argument passed to validation functions.
169
172
"""
170
173
171
174
@property
172
- def context (self ) -> Any | None :
175
+ def context (self ) -> ContextT :
173
176
"""Current validation context."""
174
177
...
175
178
@@ -180,7 +183,7 @@ def config(self) -> CoreConfig | None:
180
183
181
184
@property
182
185
def mode (self ) -> Literal ['python' , 'json' ]:
183
- """The type of input data we are currently validating"""
186
+ """The type of input data we are currently validating. """
184
187
...
185
188
186
189
@property
0 commit comments