6
6
from enum import Enum
7
7
from pathlib import Path
8
8
from typing import (
9
+ TYPE_CHECKING ,
9
10
AbstractSet ,
10
11
Any ,
11
12
Callable ,
55
56
56
57
from ._compat import ( # type: ignore[attr-defined]
57
58
IS_PYDANTIC_V2 ,
59
+ PYDANTIC_VERSION ,
58
60
BaseConfig ,
59
61
ModelField ,
60
62
ModelMetaclass ,
80
82
)
81
83
from .sql .sqltypes import GUID , AutoString
82
84
85
+ if TYPE_CHECKING :
86
+ from pydantic ._internal ._model_construction import ModelMetaclass as ModelMetaclass
87
+ from pydantic ._internal ._repr import Representation as Representation
88
+ from pydantic_core import PydanticUndefined as Undefined
89
+ from pydantic_core import PydanticUndefinedType as UndefinedType
90
+
83
91
_T = TypeVar ("_T" )
84
92
NoArgAnyCallable = Callable [[], Any ]
85
93
IncEx = Union [Set [int ], Set [str ], Dict [int , Any ], Dict [str , Any ], None ]
@@ -764,13 +772,22 @@ def model_dump(
764
772
mode : Union [Literal ["json" , "python" ], str ] = "python" ,
765
773
include : IncEx = None ,
766
774
exclude : IncEx = None ,
775
+ context : Union [Dict [str , Any ], None ] = None ,
767
776
by_alias : bool = False ,
768
777
exclude_unset : bool = False ,
769
778
exclude_defaults : bool = False ,
770
779
exclude_none : bool = False ,
771
780
round_trip : bool = False ,
772
- warnings : bool = True ,
781
+ warnings : Union [bool , Literal ["none" , "warn" , "error" ]] = True ,
782
+ serialize_as_any : bool = False ,
773
783
) -> Dict [str , Any ]:
784
+ if PYDANTIC_VERSION >= "2.7.0" :
785
+ extra_kwargs : Dict [str , Any ] = {
786
+ "context" : context ,
787
+ "serialize_as_any" : serialize_as_any ,
788
+ }
789
+ else :
790
+ extra_kwargs = {}
774
791
if IS_PYDANTIC_V2 :
775
792
return super ().model_dump (
776
793
mode = mode ,
@@ -782,6 +799,7 @@ def model_dump(
782
799
exclude_none = exclude_none ,
783
800
round_trip = round_trip ,
784
801
warnings = warnings ,
802
+ ** extra_kwargs ,
785
803
)
786
804
else :
787
805
return super ().dict (
0 commit comments