|
|
@ -45,7 +45,6 @@ sequence_types = tuple(sequence_annotation_to_type.keys()) |
|
|
|
|
|
|
|
|
mapping_annotation_to_type = { |
|
|
mapping_annotation_to_type = { |
|
|
Mapping: list, |
|
|
Mapping: list, |
|
|
List: list, |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
mapping_types = tuple(mapping_annotation_to_type.keys()) |
|
|
mapping_types = tuple(mapping_annotation_to_type.keys()) |
|
|
@ -567,16 +566,19 @@ def field_annotation_is_sequence(annotation: Union[Type[Any], None]) -> bool: |
|
|
get_origin(annotation) |
|
|
get_origin(annotation) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _annotation_is_mapping(annotation: Union[Type[Any], None]) -> bool: |
|
|
def _annotation_is_mapping(annotation: Union[Type[Any], None]) -> bool: |
|
|
if lenient_issubclass(annotation, (str, bytes)): |
|
|
if lenient_issubclass(annotation, (str, bytes)): |
|
|
return False |
|
|
return False |
|
|
return lenient_issubclass(annotation, mapping_types) |
|
|
return lenient_issubclass(annotation, mapping_types) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def field_annotation_is_mapping(annotation: Union[Type[Any], None]) -> bool: |
|
|
def field_annotation_is_mapping(annotation: Union[Type[Any], None]) -> bool: |
|
|
return _annotation_is_mapping(annotation) or _annotation_is_sequence( |
|
|
return _annotation_is_mapping(annotation) or _annotation_is_mapping( |
|
|
get_origin(annotation) |
|
|
get_origin(annotation) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def value_is_sequence(value: Any) -> bool: |
|
|
def value_is_sequence(value: Any) -> bool: |
|
|
return isinstance(value, sequence_types) and not isinstance(value, (str, bytes)) # type: ignore[arg-type] |
|
|
return isinstance(value, sequence_types) and not isinstance(value, (str, bytes)) # type: ignore[arg-type] |
|
|
|
|
|
|
|
|
@ -585,6 +587,7 @@ def _annotation_is_complex(annotation: Union[Type[Any], None]) -> bool: |
|
|
return ( |
|
|
return ( |
|
|
lenient_issubclass(annotation, (BaseModel, UploadFile)) |
|
|
lenient_issubclass(annotation, (BaseModel, UploadFile)) |
|
|
or _annotation_is_sequence(annotation) |
|
|
or _annotation_is_sequence(annotation) |
|
|
|
|
|
or _annotation_is_mapping(annotation) |
|
|
or is_dataclass(annotation) |
|
|
or is_dataclass(annotation) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
@ -623,6 +626,7 @@ def field_annotation_is_scalar_sequence(annotation: Union[Type[Any], None]) -> b |
|
|
for sub_annotation in get_args(annotation) |
|
|
for sub_annotation in get_args(annotation) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def field_annotation_is_scalar_mapping(annotation: Union[Type[Any], None]) -> bool: |
|
|
def field_annotation_is_scalar_mapping(annotation: Union[Type[Any], None]) -> bool: |
|
|
origin = get_origin(annotation) |
|
|
origin = get_origin(annotation) |
|
|
if origin is Union or origin is UnionType: |
|
|
if origin is Union or origin is UnionType: |
|
|
@ -639,7 +643,10 @@ def field_annotation_is_scalar_mapping(annotation: Union[Type[Any], None]) -> bo |
|
|
for sub_annotation in get_args(annotation) |
|
|
for sub_annotation in get_args(annotation) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
def field_annotation_is_scalar_sequence_mapping(annotation: Union[Type[Any], None]) -> bool: |
|
|
|
|
|
|
|
|
def field_annotation_is_scalar_sequence_mapping( |
|
|
|
|
|
annotation: Union[Type[Any], None] |
|
|
|
|
|
) -> bool: |
|
|
origin = get_origin(annotation) |
|
|
origin = get_origin(annotation) |
|
|
if origin is Union or origin is UnionType: |
|
|
if origin is Union or origin is UnionType: |
|
|
at_least_one_scalar_mapping = False |
|
|
at_least_one_scalar_mapping = False |
|
|
@ -651,10 +658,14 @@ def field_annotation_is_scalar_sequence_mapping(annotation: Union[Type[Any], Non |
|
|
return False |
|
|
return False |
|
|
return at_least_one_scalar_mapping |
|
|
return at_least_one_scalar_mapping |
|
|
return field_annotation_is_mapping(annotation) and all( |
|
|
return field_annotation_is_mapping(annotation) and all( |
|
|
(field_annotation_is_scalar_sequence(sub_annotation) or field_annotation_is_scalar(sub_annotation)) |
|
|
( |
|
|
|
|
|
field_annotation_is_scalar_sequence(sub_annotation) |
|
|
|
|
|
or field_annotation_is_scalar(sub_annotation) |
|
|
|
|
|
) |
|
|
for sub_annotation in get_args(annotation) |
|
|
for sub_annotation in get_args(annotation) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_bytes_or_nonable_bytes_annotation(annotation: Any) -> bool: |
|
|
def is_bytes_or_nonable_bytes_annotation(annotation: Any) -> bool: |
|
|
if lenient_issubclass(annotation, bytes): |
|
|
if lenient_issubclass(annotation, bytes): |
|
|
return True |
|
|
return True |
|
|
|