Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions django-stubs/apps/registry.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import threading
from collections.abc import Callable, Iterable
from typing import Any
from typing import Any, TypeVar

from django.db.models.base import Model

from .config import AppConfig

ModelType = type[TypeVar("ModelType", bound=Model)]

class Apps:
all_models: dict[str, dict[str, type[Model]]]
app_configs: dict[str, AppConfig]
Expand All @@ -24,7 +26,7 @@ class Apps:
def get_app_config(self, app_label: str) -> AppConfig: ...
# it's not possible to support it in plugin properly now
def get_models(self, include_auto_created: bool = ..., include_swapped: bool = ...) -> list[type[Model]]: ...
def get_model(self, app_label: str, model_name: str | None = ..., require_ready: bool = ...) -> type[Any]: ...
def get_model(self, app_label: str, model_name: str | None = ..., require_ready: bool = ...) -> ModelType: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. I don't think it can work like this. The problem is that the model class name is passed in as string to model_name argument.

With this construction I suspect it will end up being type[Any] as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works with the static type checker built into pycharm.

Copy link
Author

@false-vacuum false-vacuum Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After making this change

Screenshot_20230112_160729

Screenshot_20230112_160720


Before

Screenshot_20230112_161017

def register_model(self, app_label: str, model: type[Model]) -> None: ...
def is_installed(self, app_name: str) -> bool: ...
def get_containing_app_config(self, object_name: str) -> AppConfig | None: ...
Expand Down