11
11
from copy import deepcopy
12
12
from inspect import isclass
13
13
from types import ModuleType
14
- from typing import Any , Type , cast
14
+ from typing import Any , cast
15
15
16
16
from pypika_tortoise import Query , Table
17
17
34
34
35
35
36
36
class Tortoise :
37
- apps : dict [str , dict [str , Type ["Model" ]]] = {}
38
- table_name_generator : Callable [[Type ["Model" ]], str ] | None = None
37
+ apps : dict [str , dict [str , type ["Model" ]]] = {}
38
+ table_name_generator : Callable [[type ["Model" ]], str ] | None = None
39
39
_inited : bool = False
40
40
41
41
@classmethod
@@ -53,7 +53,7 @@ def get_connection(cls, connection_name: str) -> BaseDBAsyncClient:
53
53
54
54
@classmethod
55
55
def describe_model (
56
- cls , model : Type ["Model" ], serializable : bool = True
56
+ cls , model : type ["Model" ], serializable : bool = True
57
57
) -> dict [str , Any ]: # pragma: nocoverage
58
58
"""
59
59
Describes the given list of models or ALL registered models.
@@ -79,7 +79,7 @@ def describe_model(
79
79
80
80
@classmethod
81
81
def describe_models (
82
- cls , models : list [Type ["Model" ]] | None = None , serializable : bool = True
82
+ cls , models : list [type ["Model" ]] | None = None , serializable : bool = True
83
83
) -> dict [str , dict [str , Any ]]:
84
84
"""
85
85
Describes the given list of models or ALL registered models.
@@ -115,7 +115,7 @@ def describe_models(
115
115
116
116
@classmethod
117
117
def _init_relations (cls ) -> None :
118
- def get_related_model (related_app_name : str , related_model_name : str ) -> Type ["Model" ]:
118
+ def get_related_model (related_app_name : str , related_model_name : str ) -> type ["Model" ]:
119
119
"""
120
120
Test, if app and model really exist. Throws a ConfigurationError with a hopefully
121
121
helpful message. If successful, returns the requested model.
@@ -151,7 +151,7 @@ def split_reference(reference: str) -> tuple[str, str]:
151
151
)
152
152
return items [0 ], items [1 ]
153
153
154
- def init_fk_o2o_field (model : Type ["Model" ], field : str , is_o2o = False ) -> None :
154
+ def init_fk_o2o_field (model : type ["Model" ], field : str , is_o2o = False ) -> None :
155
155
fk_object = cast (
156
156
"OneToOneFieldInstance | ForeignKeyFieldInstance" , model ._meta .fields_map [field ]
157
157
)
@@ -284,7 +284,7 @@ def init_fk_o2o_field(model: Type["Model"], field: str, is_o2o=False) -> None:
284
284
related_model ._meta .add_field (backward_relation_name , m2m_relation )
285
285
286
286
@classmethod
287
- def _discover_models (cls , models_path : ModuleType | str , app_label : str ) -> list [Type ["Model" ]]:
287
+ def _discover_models (cls , models_path : ModuleType | str , app_label : str ) -> list [type ["Model" ]]:
288
288
if isinstance (models_path , ModuleType ):
289
289
module = models_path
290
290
else :
@@ -329,7 +329,7 @@ def init_models(
329
329
330
330
:raises ConfigurationError: If models are invalid.
331
331
"""
332
- app_models : list [Type [Model ]] = []
332
+ app_models : list [type [Model ]] = []
333
333
for models_path in models_paths :
334
334
app_models += cls ._discover_models (models_path , app_label )
335
335
@@ -399,7 +399,7 @@ async def init(
399
399
use_tz : bool = False ,
400
400
timezone : str = "UTC" ,
401
401
routers : list [str | type ] | None = None ,
402
- table_name_generator : Callable [[Type ["Model" ]], str ] | None = None ,
402
+ table_name_generator : Callable [[type ["Model" ]], str ] | None = None ,
403
403
) -> None :
404
404
"""
405
405
Sets up Tortoise-ORM: loads apps and models, configures database connections but does not
0 commit comments