From 7ea3d642c0cb0a393dd54a5efef4849ef8dd2055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 5 Jul 2023 19:21:33 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Tweak=20type=20annotations?= =?UTF-8?q?=20and=20Pydantic=20version=20range=20(#9801)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/_compat.py | 18 +++++++++++++++--- pyproject.toml | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fastapi/_compat.py b/fastapi/_compat.py index b10e1ac05..2233fe33c 100644 --- a/fastapi/_compat.py +++ b/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 diff --git a/pyproject.toml b/pyproject.toml index d9a036f43..9bf315568 100644 --- a/pyproject.toml +++ b/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"]