diff --git a/django-stubs/apps/registry.pyi b/django-stubs/apps/registry.pyi index 382535e..9cf5ed1 100644 --- a/django-stubs/apps/registry.pyi +++ b/django-stubs/apps/registry.pyi @@ -1,24 +1,22 @@ import threading -from collections import OrderedDict -from typing import Any, Callable, DefaultDict, Dict, Iterable, List, Optional, Tuple, Type, Union +from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union -from django.db.migrations.state import AppConfigStub from django.db.models.base import Model from .config import AppConfig class Apps: - all_models: Dict[str, OrderedDict[str, Type[Model]]] = ... - app_configs: OrderedDict[str, AppConfig] = ... + all_models: Dict[str, Dict[str, Type[Model]]] = ... + app_configs: Dict[str, AppConfig] = ... stored_app_configs: List[Any] = ... apps_ready: bool = ... ready_event: threading.Event = ... loading: bool = ... - _pending_operations: DefaultDict[Tuple[str, str], List] + _pending_operations: Dict[Tuple[str, str], List] models_ready: bool = ... ready: bool = ... - def __init__(self, installed_apps: Optional[Union[List[AppConfigStub], List[str], Tuple]] = ...) -> None: ... - def populate(self, installed_apps: Union[List[AppConfigStub], List[str], Tuple] = ...) -> None: ... + def __init__(self, installed_apps: Optional[Iterable[Union[AppConfig, str]]] = ...) -> None: ... + def populate(self, installed_apps: Iterable[Union[AppConfig, str]] = ...) -> None: ... def check_apps_ready(self) -> None: ... def check_models_ready(self) -> None: ... def get_app_configs(self) -> Iterable[AppConfig]: ... @@ -31,9 +29,9 @@ class Apps: def get_containing_app_config(self, object_name: str) -> Optional[AppConfig]: ... def get_registered_model(self, app_label: str, model_name: str) -> Type[Model]: ... def get_swappable_settings_name(self, to_string: str) -> Optional[str]: ... - def set_available_apps(self, available: List[str]) -> None: ... + def set_available_apps(self, available: Iterable[str]) -> None: ... def unset_available_apps(self) -> None: ... - def set_installed_apps(self, installed: Union[List[str], Tuple[str]]) -> None: ... + def set_installed_apps(self, installed: Iterable[str]) -> None: ... def unset_installed_apps(self) -> None: ... def clear_cache(self) -> None: ... def lazy_model_operation(self, function: Callable, *model_keys: Any) -> None: ... diff --git a/django-stubs/db/backends/sqlite3/base.pyi b/django-stubs/db/backends/sqlite3/base.pyi index 11535b6..a468c3e 100644 --- a/django-stubs/db/backends/sqlite3/base.pyi +++ b/django-stubs/db/backends/sqlite3/base.pyi @@ -10,3 +10,5 @@ class DatabaseWrapper(BaseDatabaseWrapper): ... FORMAT_QMARK_REGEX: Any class SQLiteCursorWrapper(Database.Cursor): ... + +def check_sqlite_version() -> None: ... diff --git a/django-stubs/db/migrations/state.pyi b/django-stubs/db/migrations/state.pyi index 7b926e6..bc1e8f2 100644 --- a/django-stubs/db/migrations/state.pyi +++ b/django-stubs/db/migrations/state.pyi @@ -1,21 +1,13 @@ -from typing import Any, DefaultDict, Dict, Iterator, List, Optional, Sequence, Tuple, Type, Union, Set +from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple, Type, Union, Set +from django.apps import AppConfig from django.apps.registry import Apps from django.db.models.base import Model from django.db.models.manager import Manager from django.db.models.fields import Field -class AppConfigStub: - apps: None - label: str - models: None - models_module: None - module: None - name: str - verbose_name: str - def __init__(self, label: str) -> None: ... - def import_models(self) -> None: ... +class AppConfigStub(AppConfig): ... class ModelState: name: str @@ -66,13 +58,7 @@ class ProjectState: def remove_model(self, app_label: str, model_name: str) -> None: ... class StateApps(Apps): - all_models: DefaultDict - apps_ready: bool - loading: bool - models_ready: bool - ready: bool real_models: List[ModelState] - stored_app_configs: List[Any] def __init__( self, real_apps: List[str], models: Dict[Tuple[str, str], ModelState], ignore_swappable: bool = ... ) -> None: ... diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index 0db5b87..9797769 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -65,7 +65,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]): null: bool = ... editable: bool = ... empty_strings_allowed: bool = ... - choices: Optional[_FieldChoices] = ... + choices: _FieldChoices = ... db_column: Optional[str] column: str default: Any diff --git a/django-stubs/db/models/options.pyi b/django-stubs/db/models/options.pyi index 5172f5e..d7fee81 100644 --- a/django-stubs/db/models/options.pyi +++ b/django-stubs/db/models/options.pyi @@ -8,6 +8,7 @@ from django.contrib.postgres.fields.array import ArrayField from django.contrib.postgres.fields.citext import CIText from django.db.backends.sqlite3.base import DatabaseWrapper from django.db.models.base import Model +from django.db.models.constraints import BaseConstraint from django.db.models.fields.mixins import FieldCacheMixin from django.db.models.fields.related import ManyToManyField, OneToOneField from django.db.models.fields.reverse_related import ForeignObjectRel @@ -34,6 +35,7 @@ _M = TypeVar("_M", bound=Model) class Options(Generic[_M]): base_manager: Manager concrete_fields: ImmutableList + constraints: List[BaseConstraint] default_manager: Manager fields: ImmutableList local_concrete_fields: ImmutableList diff --git a/scripts/enabled_test_modules.py b/scripts/enabled_test_modules.py index 6759f15..7fb01ad 100644 --- a/scripts/enabled_test_modules.py +++ b/scripts/enabled_test_modules.py @@ -2,17 +2,17 @@ # using this constant. import re -IGNORED_MODULES = {'schema', 'gis_tests', 'admin_widgets', 'admin_filters', 'migrations', +IGNORED_MODULES = {'schema', 'gis_tests', 'admin_widgets', 'admin_filters', 'sitemaps_tests', 'staticfiles_tests', 'modeladmin', 'model_forms', 'generic_views', 'forms_tests', 'flatpages_tests', 'admin_utils', - 'admin_ordering', 'admin_changelist', 'admin_views', 'redirects_tests', - 'invalid_models_tests', 'i18n', 'migrate_signals', 'model_formsets', + 'admin_ordering', 'admin_changelist', 'admin_views', + 'invalid_models_tests', 'i18n', 'model_formsets', 'template_tests', 'template_backends', 'test_runner', 'admin_scripts', - 'sites_tests', 'inline_formsets', 'foreign_object', 'cache', 'test_client', 'test_client_regress'} + 'sites_tests', 'inline_formsets', 'foreign_object', 'cache'} MOCK_OBJECTS = ['MockRequest', 'MockCompiler', 'modelz', 'call_count', 'call_args_list', 'call_args', 'MockUser', 'Xtemplate', 'DummyRequest', 'DummyUser', 'MinimalUser', 'DummyNode'] -EXTERNAL_MODULES = ['psycopg2', 'PIL', 'selenium', 'oracle', 'mysql', 'sqlite3', 'sqlparse', 'tblib', 'numpy', +EXTERNAL_MODULES = ['psycopg2', 'PIL', 'selenium', 'oracle', 'mysql', 'sqlparse', 'tblib', 'numpy', 'bcrypt', 'argon2', 'xml.dom'] IGNORED_ERRORS = { '__common__': [ @@ -65,6 +65,7 @@ IGNORED_ERRORS = { 'Incompatible types in string interpolation', '"None" has no attribute', 'has no attribute "assert', + 'Unsupported dynamic base class' ], 'aggregation': [ re.compile(r'got "Optional\[(Author|Publisher)\]", expected "Union\[(Author|Publisher), Combinable\]"'), @@ -130,7 +131,6 @@ IGNORED_ERRORS = { '"Employee" has no attribute "id"', ], 'custom_managers': [ - 'Unsupported dynamic base class', 'Incompatible types in assignment (expression has type "CharField', 'Item "Book" of "Optional[Book]" has no attribute "favorite_avg"', ], @@ -259,6 +259,20 @@ IGNORED_ERRORS = { 'middleware_exceptions': [ 'Argument 1 to "append" of "list" has incompatible type "Tuple[Any, Any]"; expected "str"' ], + 'migrate_signals': [ + 'Value of type "Optional[Any]" is not indexable', + 'Argument 1 to "set" has incompatible type "Optional[Any]"; expected "Iterable[Any]"', + ], + 'migrations': [ + 'FakeMigration', + 'FakeLoader', + '"Manager[Any]" has no attribute "args"', + 'Dict entry 0 has incompatible type "Any"', + 'Argument 1 to "append" of "list" has incompatible type', + 'base class "Model" defined the type as "Manager[Any]"', + 'Argument 1 to "RunPython" has incompatible type "str"', + + ], 'model_fields': [ 'Item "Field[Any, Any]" of "Union[Field[Any, Any], ForeignObjectRel]" has no attribute', 'Incompatible types in assignment (expression has type "Type[Person', @@ -404,6 +418,13 @@ IGNORED_ERRORS = { '"PossessedCar" has no attribute "color"', 'expression has type "None", variable has type "List[str]"', ], + 'test_client': [ + '(expression has type "HttpResponse", variable has type "StreamingHttpResponse")' + ], + 'test_client_regress': [ + '(expression has type "Dict[, ]", variable has type "SessionBase")', + 'Unsupported left operand type for + ("None")', + ], 'transactions': [ 'Incompatible types in assignment (expression has type "Thread", variable has type "Callable[[], Any]")' ], diff --git a/test-data/typecheck/test_import_all.yml b/test-data/typecheck/test_import_all.yml index c530aab..3540fa9 100644 --- a/test-data/typecheck/test_import_all.yml +++ b/test-data/typecheck/test_import_all.yml @@ -270,6 +270,7 @@ import django.db.models.constraints import django.db.models.deletion import django.db.models.expressions + import django.db.models.enums import django.db.models.fields import django.db.models.fields.files import django.db.models.fields.mixins