check against optional in annotation str
This commit is contained in:
parent
d3fbf123b5
commit
3fb8450fb5
@ -281,7 +281,19 @@ def true_type_for_pydantic_field(f: ModelField):
|
|||||||
"""
|
"""
|
||||||
if not isinstance(f.annotation, (str, ForwardRef)):
|
if not isinstance(f.annotation, (str, ForwardRef)):
|
||||||
return f.annotation
|
return f.annotation
|
||||||
return f.outer_type_
|
|
||||||
|
type_ = f.outer_type_
|
||||||
|
|
||||||
|
if (
|
||||||
|
(isinstance(f.annotation, str) and f.annotation.startswith("Optional"))
|
||||||
|
or (
|
||||||
|
isinstance(f.annotation, ForwardRef)
|
||||||
|
and f.annotation.__forward_arg__.startswith("Optional")
|
||||||
|
)
|
||||||
|
) and not is_optional(type_):
|
||||||
|
return Optional[type_]
|
||||||
|
|
||||||
|
return type_
|
||||||
|
|
||||||
|
|
||||||
def value_inside_optional(cls: GenericType) -> GenericType:
|
def value_inside_optional(cls: GenericType) -> GenericType:
|
||||||
|
Loading…
Reference in New Issue
Block a user