From aa814e24bc18bd7fcce08c661f228eb41ffd0e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 7 Oct 2024 23:21:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20Fix=20types=20for=20new=20Pydant?= =?UTF-8?q?ic=20(#1131)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqlmodel/main.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 1597e4e04f..3532e81a8e 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -52,7 +52,7 @@ from sqlalchemy.orm.instrumentation import is_instrumented from sqlalchemy.sql.schema import MetaData from sqlalchemy.sql.sqltypes import LargeBinary, Time, Uuid -from typing_extensions import Literal, deprecated, get_origin +from typing_extensions import Literal, TypeAlias, deprecated, get_origin from ._compat import ( # type: ignore[attr-defined] IS_PYDANTIC_V2, @@ -90,7 +90,12 @@ _T = TypeVar("_T") NoArgAnyCallable = Callable[[], Any] -IncEx = Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any], None] +IncEx: TypeAlias = Union[ + Set[int], + Set[str], + Mapping[int, Union["IncEx", Literal[True]]], + Mapping[str, Union["IncEx", Literal[True]]], +] OnDeleteType = Literal["CASCADE", "SET NULL", "RESTRICT"] @@ -858,8 +863,8 @@ def model_dump( self, *, mode: Union[Literal["json", "python"], str] = "python", - include: IncEx = None, - exclude: IncEx = None, + include: Union[IncEx, None] = None, + exclude: Union[IncEx, None] = None, context: Union[Dict[str, Any], None] = None, by_alias: bool = False, exclude_unset: bool = False, @@ -908,8 +913,8 @@ def model_dump( def dict( self, *, - include: IncEx = None, - exclude: IncEx = None, + include: Union[IncEx, None] = None, + exclude: Union[IncEx, None] = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False,