add a number of django test directories for typecheck (#257)

This commit is contained in:
Maksim Kurnikov
2019-12-11 00:51:32 +03:00
committed by GitHub
parent d43c6dc7e2
commit 8c2de7da56
7 changed files with 44 additions and 34 deletions

View File

@@ -1,24 +1,22 @@
import threading import threading
from collections import OrderedDict from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, Union
from typing import Any, Callable, DefaultDict, Dict, Iterable, List, Optional, Tuple, Type, Union
from django.db.migrations.state import AppConfigStub
from django.db.models.base import Model from django.db.models.base import Model
from .config import AppConfig from .config import AppConfig
class Apps: class Apps:
all_models: Dict[str, OrderedDict[str, Type[Model]]] = ... all_models: Dict[str, Dict[str, Type[Model]]] = ...
app_configs: OrderedDict[str, AppConfig] = ... app_configs: Dict[str, AppConfig] = ...
stored_app_configs: List[Any] = ... stored_app_configs: List[Any] = ...
apps_ready: bool = ... apps_ready: bool = ...
ready_event: threading.Event = ... ready_event: threading.Event = ...
loading: bool = ... loading: bool = ...
_pending_operations: DefaultDict[Tuple[str, str], List] _pending_operations: Dict[Tuple[str, str], List]
models_ready: bool = ... models_ready: bool = ...
ready: bool = ... ready: bool = ...
def __init__(self, installed_apps: Optional[Union[List[AppConfigStub], List[str], Tuple]] = ...) -> None: ... def __init__(self, installed_apps: Optional[Iterable[Union[AppConfig, str]]] = ...) -> None: ...
def populate(self, installed_apps: Union[List[AppConfigStub], List[str], Tuple] = ...) -> None: ... def populate(self, installed_apps: Iterable[Union[AppConfig, str]] = ...) -> None: ...
def check_apps_ready(self) -> None: ... def check_apps_ready(self) -> None: ...
def check_models_ready(self) -> None: ... def check_models_ready(self) -> None: ...
def get_app_configs(self) -> Iterable[AppConfig]: ... 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_containing_app_config(self, object_name: str) -> Optional[AppConfig]: ...
def get_registered_model(self, app_label: str, model_name: str) -> Type[Model]: ... 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 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 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 unset_installed_apps(self) -> None: ...
def clear_cache(self) -> None: ... def clear_cache(self) -> None: ...
def lazy_model_operation(self, function: Callable, *model_keys: Any) -> None: ... def lazy_model_operation(self, function: Callable, *model_keys: Any) -> None: ...

View File

@@ -10,3 +10,5 @@ class DatabaseWrapper(BaseDatabaseWrapper): ...
FORMAT_QMARK_REGEX: Any FORMAT_QMARK_REGEX: Any
class SQLiteCursorWrapper(Database.Cursor): ... class SQLiteCursorWrapper(Database.Cursor): ...
def check_sqlite_version() -> None: ...

View File

@@ -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.apps.registry import Apps
from django.db.models.base import Model from django.db.models.base import Model
from django.db.models.manager import Manager from django.db.models.manager import Manager
from django.db.models.fields import Field from django.db.models.fields import Field
class AppConfigStub: class AppConfigStub(AppConfig): ...
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 ModelState: class ModelState:
name: str name: str
@@ -66,13 +58,7 @@ class ProjectState:
def remove_model(self, app_label: str, model_name: str) -> None: ... def remove_model(self, app_label: str, model_name: str) -> None: ...
class StateApps(Apps): class StateApps(Apps):
all_models: DefaultDict
apps_ready: bool
loading: bool
models_ready: bool
ready: bool
real_models: List[ModelState] real_models: List[ModelState]
stored_app_configs: List[Any]
def __init__( def __init__(
self, real_apps: List[str], models: Dict[Tuple[str, str], ModelState], ignore_swappable: bool = ... self, real_apps: List[str], models: Dict[Tuple[str, str], ModelState], ignore_swappable: bool = ...
) -> None: ... ) -> None: ...

View File

@@ -65,7 +65,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
null: bool = ... null: bool = ...
editable: bool = ... editable: bool = ...
empty_strings_allowed: bool = ... empty_strings_allowed: bool = ...
choices: Optional[_FieldChoices] = ... choices: _FieldChoices = ...
db_column: Optional[str] db_column: Optional[str]
column: str column: str
default: Any default: Any

View File

@@ -8,6 +8,7 @@ from django.contrib.postgres.fields.array import ArrayField
from django.contrib.postgres.fields.citext import CIText from django.contrib.postgres.fields.citext import CIText
from django.db.backends.sqlite3.base import DatabaseWrapper from django.db.backends.sqlite3.base import DatabaseWrapper
from django.db.models.base import Model 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.mixins import FieldCacheMixin
from django.db.models.fields.related import ManyToManyField, OneToOneField from django.db.models.fields.related import ManyToManyField, OneToOneField
from django.db.models.fields.reverse_related import ForeignObjectRel from django.db.models.fields.reverse_related import ForeignObjectRel
@@ -34,6 +35,7 @@ _M = TypeVar("_M", bound=Model)
class Options(Generic[_M]): class Options(Generic[_M]):
base_manager: Manager base_manager: Manager
concrete_fields: ImmutableList concrete_fields: ImmutableList
constraints: List[BaseConstraint]
default_manager: Manager default_manager: Manager
fields: ImmutableList fields: ImmutableList
local_concrete_fields: ImmutableList local_concrete_fields: ImmutableList

View File

@@ -2,17 +2,17 @@
# using this constant. # using this constant.
import re 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', 'sitemaps_tests', 'staticfiles_tests', 'modeladmin', 'model_forms',
'generic_views', 'forms_tests', 'flatpages_tests', 'admin_utils', 'generic_views', 'forms_tests', 'flatpages_tests', 'admin_utils',
'admin_ordering', 'admin_changelist', 'admin_views', 'redirects_tests', 'admin_ordering', 'admin_changelist', 'admin_views',
'invalid_models_tests', 'i18n', 'migrate_signals', 'model_formsets', 'invalid_models_tests', 'i18n', 'model_formsets',
'template_tests', 'template_backends', 'test_runner', 'admin_scripts', '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', MOCK_OBJECTS = ['MockRequest', 'MockCompiler', 'modelz', 'call_count', 'call_args_list',
'call_args', 'MockUser', 'Xtemplate', 'DummyRequest', 'DummyUser', 'MinimalUser', 'DummyNode'] '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'] 'bcrypt', 'argon2', 'xml.dom']
IGNORED_ERRORS = { IGNORED_ERRORS = {
'__common__': [ '__common__': [
@@ -65,6 +65,7 @@ IGNORED_ERRORS = {
'Incompatible types in string interpolation', 'Incompatible types in string interpolation',
'"None" has no attribute', '"None" has no attribute',
'has no attribute "assert', 'has no attribute "assert',
'Unsupported dynamic base class'
], ],
'aggregation': [ 'aggregation': [
re.compile(r'got "Optional\[(Author|Publisher)\]", expected "Union\[(Author|Publisher), Combinable\]"'), re.compile(r'got "Optional\[(Author|Publisher)\]", expected "Union\[(Author|Publisher), Combinable\]"'),
@@ -130,7 +131,6 @@ IGNORED_ERRORS = {
'"Employee" has no attribute "id"', '"Employee" has no attribute "id"',
], ],
'custom_managers': [ 'custom_managers': [
'Unsupported dynamic base class',
'Incompatible types in assignment (expression has type "CharField', 'Incompatible types in assignment (expression has type "CharField',
'Item "Book" of "Optional[Book]" has no attribute "favorite_avg"', 'Item "Book" of "Optional[Book]" has no attribute "favorite_avg"',
], ],
@@ -259,6 +259,20 @@ IGNORED_ERRORS = {
'middleware_exceptions': [ 'middleware_exceptions': [
'Argument 1 to "append" of "list" has incompatible type "Tuple[Any, Any]"; expected "str"' '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': [ 'model_fields': [
'Item "Field[Any, Any]" of "Union[Field[Any, Any], ForeignObjectRel]" has no attribute', 'Item "Field[Any, Any]" of "Union[Field[Any, Any], ForeignObjectRel]" has no attribute',
'Incompatible types in assignment (expression has type "Type[Person', 'Incompatible types in assignment (expression has type "Type[Person',
@@ -404,6 +418,13 @@ IGNORED_ERRORS = {
'"PossessedCar" has no attribute "color"', '"PossessedCar" has no attribute "color"',
'expression has type "None", variable has type "List[str]"', '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[<nothing>, <nothing>]", variable has type "SessionBase")',
'Unsupported left operand type for + ("None")',
],
'transactions': [ 'transactions': [
'Incompatible types in assignment (expression has type "Thread", variable has type "Callable[[], Any]")' 'Incompatible types in assignment (expression has type "Thread", variable has type "Callable[[], Any]")'
], ],

View File

@@ -270,6 +270,7 @@
import django.db.models.constraints import django.db.models.constraints
import django.db.models.deletion import django.db.models.deletion
import django.db.models.expressions import django.db.models.expressions
import django.db.models.enums
import django.db.models.fields import django.db.models.fields
import django.db.models.fields.files import django.db.models.fields.files
import django.db.models.fields.mixins import django.db.models.fields.mixins