33from enum import Enum
44from functools import reduce
55from itertools import chain
6- from typing import Any , Dict , List , Optional , no_type_check , Union
7- from typing_extensions import get_origin , get_args
6+ from typing import Any , Dict , List , Optional , Union , no_type_check
87
98from django .core .serializers .json import DjangoJSONEncoder
109from django .db .models import Manager , Model
1312from django .utils .encoding import force_str
1413from django .utils .functional import Promise
1514from pydantic import BaseModel , create_model
16- from pydantic .errors import PydanticUserError
1715from pydantic ._internal ._model_construction import ModelMetaclass
16+ from pydantic .errors import PydanticUserError
17+ from typing_extensions import get_args , get_origin
1818
1919if sys .version_info >= (3 , 10 ):
2020 from types import UnionType
@@ -54,7 +54,6 @@ def __new__(mcs, name: str, bases: tuple, namespace: dict, **kwargs):
5454 and issubclass (base , ModelSchema )
5555 and base == ModelSchema
5656 ):
57-
5857 config = namespace ["model_config" ]
5958 include = config .get ("include" , None )
6059 exclude = config .get ("exclude" , None )
@@ -103,7 +102,6 @@ def __new__(mcs, name: str, bases: tuple, namespace: dict, **kwargs):
103102 python_type = None
104103 pydantic_field = None
105104 if field_name in annotations and field_name in namespace :
106-
107105 python_type = annotations .pop (field_name )
108106 pydantic_field = namespace [field_name ]
109107 if (
@@ -143,10 +141,10 @@ def __new__(mcs, name: str, bases: tuple, namespace: dict, **kwargs):
143141def _is_optional_field (annotation ) -> bool :
144142 args = get_args (annotation )
145143 return (
146- (get_origin (annotation ) is Union or get_origin (annotation ) is UnionType )
147- and type (None ) in args
148- and len (args ) == 2
149- and any (inspect .isclass (arg ) and issubclass (arg , ModelSchema ) for arg in args )
144+ (get_origin (annotation ) is Union or get_origin (annotation ) is UnionType )
145+ and type (None ) in args
146+ and len (args ) == 2
147+ and any (inspect .isclass (arg ) and issubclass (arg , ModelSchema ) for arg in args )
150148 )
151149
152150
@@ -221,7 +219,9 @@ def dict(self) -> dict:
221219 non_none_type_annotation = next (
222220 arg for arg in get_args (annotation ) if arg is not type (None )
223221 )
224- data [key ] = self ._get_annotation_objects (value , non_none_type_annotation )
222+ data [key ] = self ._get_annotation_objects (
223+ value , non_none_type_annotation
224+ )
225225
226226 elif inspect .isclass (annotation ) and issubclass (annotation , ModelSchema ):
227227 data [key ] = self ._get_annotation_objects (self .get (key ), annotation )
@@ -232,7 +232,6 @@ def dict(self) -> dict:
232232
233233
234234class ModelSchema (BaseModel , metaclass = ModelSchemaMetaclass ):
235-
236235 def __eq__ (self , other : Any ) -> bool :
237236 result = super ().__eq__ (other )
238237 if isinstance (result , bool ):
0 commit comments