2
2
3
3
import os
4
4
import inspect
5
- from typing import TYPE_CHECKING , Any , Type , Union , Generic , TypeVar , Callable , Optional , cast
5
+ from typing import TYPE_CHECKING , Any , Type , Union , Generic , TypeVar , Callable , cast
6
6
from datetime import date , datetime
7
7
from typing_extensions import (
8
- List ,
9
8
Unpack ,
10
9
Literal ,
11
10
ClassVar ,
@@ -367,7 +366,7 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
367
366
if type_ is None :
368
367
raise RuntimeError (f"Unexpected field type is None for { key } " )
369
368
370
- return construct_type (value = value , type_ = type_ , metadata = getattr ( field , "metadata" , None ) )
369
+ return construct_type (value = value , type_ = type_ )
371
370
372
371
373
372
def is_basemodel (type_ : type ) -> bool :
@@ -421,7 +420,7 @@ def construct_type_unchecked(*, value: object, type_: type[_T]) -> _T:
421
420
return cast (_T , construct_type (value = value , type_ = type_ ))
422
421
423
422
424
- def construct_type (* , value : object , type_ : object , metadata : Optional [ List [ Any ]] = None ) -> object :
423
+ def construct_type (* , value : object , type_ : object ) -> object :
425
424
"""Loose coercion to the expected type with construction of nested values.
426
425
427
426
If the given value does not match the expected type then it is returned as-is.
@@ -439,10 +438,8 @@ def construct_type(*, value: object, type_: object, metadata: Optional[List[Any]
439
438
type_ = type_ .__value__ # type: ignore[unreachable]
440
439
441
440
# unwrap `Annotated[T, ...]` -> `T`
442
- if metadata is not None :
443
- meta : tuple [Any , ...] = tuple (metadata )
444
- elif is_annotated_type (type_ ):
445
- meta = get_args (type_ )[1 :]
441
+ if is_annotated_type (type_ ):
442
+ meta : tuple [Any , ...] = get_args (type_ )[1 :]
446
443
type_ = extract_type_arg (type_ , 0 )
447
444
else :
448
445
meta = tuple ()
0 commit comments