Browse Source

♻️ Tweak type annotations and Pydantic version range (#9801)

pull/9814/head
Sebastián Ramírez 2 years ago
committed by GitHub
parent
commit
7ea3d642c0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      fastapi/_compat.py
  2. 2
      pyproject.toml

18
fastapi/_compat.py

@ -201,11 +201,18 @@ if PYDANTIC_V2:
fields: List[ModelField],
schema_generator: GenerateJsonSchema,
model_name_map: ModelNameMap,
) -> Tuple[Dict[str, Any], Dict[str, Dict[str, Any]]]:
) -> Tuple[
Dict[
Tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue
],
Dict[str, Dict[str, Any]],
]:
inputs = [
(field, field.mode, field._type_adapter.core_schema) for field in fields
]
field_mapping, definitions = schema_generator.generate_definitions(inputs=inputs) # type: ignore[arg-type]
field_mapping, definitions = schema_generator.generate_definitions(
inputs=inputs
)
return field_mapping, definitions # type: ignore[return-value]
def is_scalar_field(field: ModelField) -> bool:
@ -441,7 +448,12 @@ else:
fields: List[ModelField],
schema_generator: GenerateJsonSchema,
model_name_map: ModelNameMap,
) -> Tuple[Dict[str, Any], Dict[str, Dict[str, Any]]]:
) -> Tuple[
Dict[
Tuple[ModelField, Literal["validation", "serialization"]], JsonSchemaValue
],
Dict[str, Dict[str, Any]],
]:
models = get_flat_models_from_fields(fields, known_models=set())
return {}, get_model_definitions(
flat_models=models, model_name_map=model_name_map

2
pyproject.toml

@ -43,7 +43,7 @@ classifiers = [
dependencies = [
"starlette>=0.27.0,<0.28.0",
# TODO (pv2): re-enable this
# "pydantic>=1.7.4,!=1.8,!=1.8.1,<3.0.0",
# "pydantic>=1.7.4,!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,<3.0.0",
"typing-extensions>=4.5.0",
]
dynamic = ["version"]

Loading…
Cancel
Save