Browse Source

🎨 Tweak types

pull/14564/head
Sebastián Ramírez 7 months ago
parent
commit
8491eee340
  1. 4
      fastapi/_compat/shared.py
  2. 2
      fastapi/_compat/v2.py
  3. 2
      fastapi/dependencies/utils.py

4
fastapi/_compat/shared.py

@ -60,7 +60,7 @@ def lenient_issubclass(
def _annotation_is_sequence(annotation: Union[type[Any], None]) -> bool: def _annotation_is_sequence(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, sequence_types) # type: ignore[arg-type] return lenient_issubclass(annotation, sequence_types)
def field_annotation_is_sequence(annotation: Union[type[Any], None]) -> bool: def field_annotation_is_sequence(annotation: Union[type[Any], None]) -> bool:
@ -76,7 +76,7 @@ def field_annotation_is_sequence(annotation: Union[type[Any], None]) -> bool:
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))
def _annotation_is_complex(annotation: Union[type[Any], None]) -> bool: def _annotation_is_complex(annotation: Union[type[Any], None]) -> bool:

2
fastapi/_compat/v2.py

@ -457,7 +457,7 @@ def serialize_sequence_value(*, field: ModelField, value: Any) -> Sequence[Any]:
origin_type = get_origin(union_arg) or union_arg origin_type = get_origin(union_arg) or union_arg
break break
assert issubclass(origin_type, shared.sequence_types) # type: ignore[arg-type] assert issubclass(origin_type, shared.sequence_types) # type: ignore[arg-type]
return shared.sequence_annotation_to_type[origin_type](value) # type: ignore[no-any-return] return shared.sequence_annotation_to_type[origin_type](value) # type: ignore[no-any-return,index]
def get_missing_field_error(loc: tuple[str, ...]) -> dict[str, Any]: def get_missing_field_error(loc: tuple[str, ...]) -> dict[str, Any]:

2
fastapi/dependencies/utils.py

@ -915,7 +915,7 @@ async def _extract_form_body(
and value_is_sequence(value) and value_is_sequence(value)
): ):
# For types # For types
assert isinstance(value, sequence_types) # type: ignore[arg-type] assert isinstance(value, sequence_types)
results: list[Union[bytes, str]] = [] results: list[Union[bytes, str]] = []
async def process_fn( async def process_fn(

Loading…
Cancel
Save