@@ -185,33 +185,44 @@ class Request(BaseModel):
185185 method : HttpMethod = 'GET'
186186 """HTTP request method."""
187187
188- headers : Annotated [HttpHeaders , Field (default_factory = HttpHeaders )] = HttpHeaders ()
189- """HTTP request headers."""
190-
191188 payload : Annotated [
192189 HttpPayload | None ,
193190 BeforeValidator (lambda v : v .encode () if isinstance (v , str ) else v ),
194191 PlainSerializer (lambda v : v .decode () if isinstance (v , bytes ) else v ),
195192 ] = None
196193 """HTTP request payload."""
197194
198- user_data : Annotated [
199- dict [str , JsonSerializable ], # Internally, the model contains `UserData`, this is just for convenience
200- Field (alias = 'userData' , default_factory = lambda : UserData ()),
201- PlainValidator (user_data_adapter .validate_python ),
202- PlainSerializer (
203- lambda instance : user_data_adapter .dump_python (
204- instance ,
205- by_alias = True ,
206- exclude_none = True ,
207- exclude_unset = True ,
208- exclude_defaults = True ,
209- )
210- ),
211- ] = {}
212- """Custom user data assigned to the request. Use this to save any request related data to the
213- request's scope, keeping them accessible on retries, failures etc.
214- """
195+ # Workaround for pydantic 2.12 and mypy type checking issue for Annotated with default_factory
196+ if TYPE_CHECKING :
197+ headers : HttpHeaders = HttpHeaders ()
198+ """HTTP request headers."""
199+
200+ user_data : dict [str , JsonSerializable ] = {}
201+ """Custom user data assigned to the request. Use this to save any request related data to the
202+ request's scope, keeping them accessible on retries, failures etc.
203+ """
204+
205+ else :
206+ headers : Annotated [HttpHeaders , Field (default_factory = HttpHeaders )]
207+ """HTTP request headers."""
208+
209+ user_data : Annotated [
210+ dict [str , JsonSerializable ], # Internally, the model contains `UserData`, this is just for convenience
211+ Field (alias = 'userData' , default_factory = lambda : UserData ()),
212+ PlainValidator (user_data_adapter .validate_python ),
213+ PlainSerializer (
214+ lambda instance : user_data_adapter .dump_python (
215+ instance ,
216+ by_alias = True ,
217+ exclude_none = True ,
218+ exclude_unset = True ,
219+ exclude_defaults = True ,
220+ )
221+ ),
222+ ]
223+ """Custom user data assigned to the request. Use this to save any request related data to the
224+ request's scope, keeping them accessible on retries, failures etc.
225+ """
215226
216227 retry_count : Annotated [int , Field (alias = 'retryCount' )] = 0
217228 """Number of times the request has been retried."""
0 commit comments