Closed last-partizan closed 1 year ago
Hmm, I think this would be tricky without some code gen / compiler magic since apps.get_model
only has a string as its param.
https://docs.djangoproject.com/en/4.0/ref/applications/#django.apps.apps.get_model
One option would be to make them return Any
, which might be more practical than Model
I was thinking about
_M = TypeVar("_M", bound=Model)
...
def get_model(
self, app_label: str, model_name: Optional[str] = ..., require_ready: bool = ...
) -> Type[_M]: ...
But, probably it's best to be left it in it's current state. When i know which types i will be getting - it's easier to just import them.
I found myself doing something like this
Both of those functions are returning
Model
, which triggers type error when i want to specify exact type.Is there a way to make
Model
compatible with it's subclasses?