1
1
from collections .abc import Mapping
2
- from typing import Type
2
+ from typing import Tuple , Type , cast
3
3
4
4
from django .db .migrations .state import ModelState
5
5
from django .db .models import Model
@@ -17,8 +17,8 @@ class PostgresModelState(ModelState):
17
17
"""
18
18
19
19
@classmethod
20
- def from_model (
21
- cls , model : PostgresModel , * args , ** kwargs
20
+ def from_model ( # type: ignore[override]
21
+ cls , model : Type [ PostgresModel ] , * args , ** kwargs
22
22
) -> "PostgresModelState" :
23
23
"""Creates a new :see:PostgresModelState object from the specified
24
24
model.
@@ -29,28 +29,32 @@ def from_model(
29
29
We also need to patch up the base class for the model.
30
30
"""
31
31
32
- model_state = super ().from_model (model , * args , ** kwargs )
33
- model_state = cls ._pre_new (model , model_state )
32
+ model_state = super ().from_model (
33
+ cast (Type [Model ], model ), * args , ** kwargs
34
+ )
35
+ model_state = cls ._pre_new (
36
+ model , cast ("PostgresModelState" , model_state )
37
+ )
34
38
35
39
# django does not add abstract bases as a base in migrations
36
40
# because it assumes the base does not add anything important
37
41
# in a migration.. but it does, so we replace the Model
38
42
# base with the actual base
39
- bases = tuple ()
43
+ bases : Tuple [ Type [ Model ], ...] = tuple ()
40
44
for base in model_state .bases :
41
45
if issubclass (base , Model ):
42
46
bases += (cls ._get_base_model_class (),)
43
47
else :
44
48
bases += (base ,)
45
49
46
- model_state .bases = bases
50
+ model_state .bases = cast ( Tuple [ Type [ Model ]], bases )
47
51
return model_state
48
52
49
53
def clone (self ) -> "PostgresModelState" :
50
54
"""Gets an exact copy of this :see:PostgresModelState."""
51
55
52
56
model_state = super ().clone ()
53
- return self ._pre_clone (model_state )
57
+ return self ._pre_clone (cast ( PostgresModelState , model_state ) )
54
58
55
59
def render (self , apps ):
56
60
"""Renders this state into an actual model."""
@@ -95,7 +99,9 @@ def render(self, apps):
95
99
96
100
@classmethod
97
101
def _pre_new (
98
- cls , model : PostgresModel , model_state : "PostgresModelState"
102
+ cls ,
103
+ model : Type [PostgresModel ],
104
+ model_state : "PostgresModelState" ,
99
105
) -> "PostgresModelState" :
100
106
"""Called when a new model state is created from the specified
101
107
model."""
0 commit comments