11from collections .abc import Mapping
2- from typing import Type
2+ from typing import Tuple , Type , cast
33
44from django .db .migrations .state import ModelState
55from django .db .models import Model
@@ -17,8 +17,8 @@ class PostgresModelState(ModelState):
1717 """
1818
1919 @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
2222 ) -> "PostgresModelState" :
2323 """Creates a new :see:PostgresModelState object from the specified
2424 model.
@@ -29,28 +29,32 @@ def from_model(
2929 We also need to patch up the base class for the model.
3030 """
3131
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+ )
3438
3539 # django does not add abstract bases as a base in migrations
3640 # because it assumes the base does not add anything important
3741 # in a migration.. but it does, so we replace the Model
3842 # base with the actual base
39- bases = tuple ()
43+ bases : Tuple [ Type [ Model ], ...] = tuple ()
4044 for base in model_state .bases :
4145 if issubclass (base , Model ):
4246 bases += (cls ._get_base_model_class (),)
4347 else :
4448 bases += (base ,)
4549
46- model_state .bases = bases
50+ model_state .bases = cast ( Tuple [ Type [ Model ]], bases )
4751 return model_state
4852
4953 def clone (self ) -> "PostgresModelState" :
5054 """Gets an exact copy of this :see:PostgresModelState."""
5155
5256 model_state = super ().clone ()
53- return self ._pre_clone (model_state )
57+ return self ._pre_clone (cast ( PostgresModelState , model_state ) )
5458
5559 def render (self , apps ):
5660 """Renders this state into an actual model."""
@@ -95,7 +99,9 @@ def render(self, apps):
9599
96100 @classmethod
97101 def _pre_new (
98- cls , model : PostgresModel , model_state : "PostgresModelState"
102+ cls ,
103+ model : Type [PostgresModel ],
104+ model_state : "PostgresModelState" ,
99105 ) -> "PostgresModelState" :
100106 """Called when a new model state is created from the specified
101107 model."""
0 commit comments