diff --git a/dev-requirements.txt b/dev-requirements.txt index 48bdc28..be3f224 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,7 @@ black pytest-mypy-plugins==1.1.0 psycopg2 -flake8==3.7.8 +flake8==3.7.9 flake8-pyi==19.3.0 isort==4.3.21 gitpython==3.0.5 diff --git a/django-stubs/contrib/admin/checks.pyi b/django-stubs/contrib/admin/checks.pyi index 6bb0e36..ba57692 100644 --- a/django-stubs/contrib/admin/checks.pyi +++ b/django-stubs/contrib/admin/checks.pyi @@ -1,11 +1,13 @@ -from typing import Any, List, Union +from typing import Any, List, Union, Iterable, Optional from django.contrib.admin.options import BaseModelAdmin from django.core.checks.messages import Error +from django.apps.config import AppConfig + _CheckError = Union[str, Error] -def check_admin_app(app_configs: None, **kwargs: Any) -> List[_CheckError]: ... +def check_admin_app(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[_CheckError]: ... def check_dependencies(**kwargs: Any) -> List[_CheckError]: ... class BaseModelAdminChecks: diff --git a/django-stubs/contrib/admin/sites.pyi b/django-stubs/contrib/admin/sites.pyi index 9a18ed2..7601e2e 100644 --- a/django-stubs/contrib/admin/sites.pyi +++ b/django-stubs/contrib/admin/sites.pyi @@ -8,6 +8,8 @@ from django.template.response import TemplateResponse from django.urls.resolvers import URLResolver from django.utils.functional import LazyObject +from django.apps.config import AppConfig + all_sites: Any class AlreadyRegistered(Exception): ... @@ -28,7 +30,7 @@ class AdminSite: name: str = ... _registry: Dict[Type[Model], ModelAdmin] def __init__(self, name: str = ...) -> None: ... - def check(self, app_configs: None) -> List[Any]: ... + def check(self, app_configs: Optional[Iterable[AppConfig]]) -> List[Any]: ... def register( self, model_or_iterable: Union[Type[Model], Iterable[Type[Model]]], @@ -37,7 +39,7 @@ class AdminSite: ) -> None: ... def unregister(self, model_or_iterable: Union[Type[Model], Iterable[Type[Model]]]) -> None: ... def is_registered(self, model: Type[Model]) -> bool: ... - def add_action(self, action: Callable, name: None = ...) -> None: ... + def add_action(self, action: Callable, name: Optional[str] = ...) -> None: ... def disable_action(self, name: str) -> None: ... def get_action(self, name: str) -> Callable: ... @property @@ -52,14 +54,20 @@ class AdminSite: @property def urls(self) -> Tuple[List[URLResolver], str, str]: ... def each_context(self, request: Any): ... - def password_change(self, request: WSGIRequest, extra_context: Dict[str, str] = ...) -> TemplateResponse: ... - def password_change_done(self, request: WSGIRequest, extra_context: None = ...) -> TemplateResponse: ... + def password_change( + self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ... + ) -> TemplateResponse: ... + def password_change_done( + self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ... + ) -> TemplateResponse: ... def i18n_javascript(self, request: WSGIRequest, extra_context: Optional[Dict[Any, Any]] = ...) -> HttpResponse: ... - def logout(self, request: WSGIRequest, extra_context: None = ...) -> TemplateResponse: ... - def login(self, request: WSGIRequest, extra_context: None = ...) -> HttpResponse: ... + def logout(self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ... + def login(self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...) -> HttpResponse: ... def get_app_list(self, request: WSGIRequest) -> List[Any]: ... - def index(self, request: WSGIRequest, extra_context: Optional[Dict[str, str]] = ...) -> TemplateResponse: ... - def app_index(self, request: WSGIRequest, app_label: str, extra_context: None = ...) -> TemplateResponse: ... + def index(self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...) -> TemplateResponse: ... + def app_index( + self, request: WSGIRequest, app_label: str, extra_context: Optional[Dict[str, Any]] = ... + ) -> TemplateResponse: ... class DefaultAdminSite(LazyObject): ... diff --git a/django-stubs/contrib/admin/utils.pyi b/django-stubs/contrib/admin/utils.pyi index cc54957..b127166 100644 --- a/django-stubs/contrib/admin/utils.pyi +++ b/django-stubs/contrib/admin/utils.pyi @@ -9,12 +9,10 @@ from django.contrib.auth.forms import AdminPasswordChangeForm from django.core.handlers.wsgi import WSGIRequest from django.db.models.base import Model from django.db.models.deletion import Collector -from django.db.models.fields.mixins import FieldCacheMixin from django.db.models.fields.reverse_related import ManyToOneRel from django.db.models.options import Options from django.db.models.query import QuerySet from django.forms.forms import BaseForm -from django.utils.safestring import SafeText from django.db.models.fields import Field, reverse_related @@ -27,7 +25,7 @@ def unquote(s: str) -> str: ... def flatten(fields: Any) -> List[Union[Callable, str]]: ... def flatten_fieldsets(fieldsets: Any) -> List[Union[Callable, str]]: ... def get_deleted_objects( - objs: QuerySet, request: WSGIRequest, admin_site: AdminSite + objs: Sequence[Optional[Model]], request: WSGIRequest, admin_site: AdminSite ) -> Tuple[List[Any], Dict[Any, Any], Set[Any], List[Any]]: ... class NestedObjects(Collector): @@ -41,22 +39,14 @@ class NestedObjects(Collector): model_objs: Any = ... def __init__(self, *args: Any, **kwargs: Any) -> None: ... def add_edge(self, source: Optional[Model], target: Model) -> None: ... - def collect( - self, - objs: Union[Sequence[Optional[Model]], QuerySet], - source: Optional[Type[Model]] = ..., - source_attr: Optional[str] = ..., - **kwargs: Any - ) -> None: ... - def related_objects(self, related: ManyToOneRel, objs: List[Model]) -> QuerySet: ... - def nested(self, format_callback: Callable = ...) -> Union[List[SafeText], List[int]]: ... - def can_fast_delete(self, *args: Any, **kwargs: Any) -> bool: ... + def related_objects(self, related: ManyToOneRel, objs: Sequence[Optional[Model]]) -> QuerySet: ... + def nested(self, format_callback: Callable = ...) -> List[Any]: ... def model_format_dict(obj: Any): ... def model_ngettext(obj: Union[Options, QuerySet], n: Optional[int] = ...) -> str: ... def lookup_field( name: Union[Callable, str], obj: Model, model_admin: BaseModelAdmin = ... -) -> Tuple[Optional[Field], Callable, Callable]: ... +) -> Tuple[Optional[Field], Any, Any]: ... def label_for_field( name: Union[Callable, str], model: Type[Model], @@ -65,16 +55,14 @@ def label_for_field( form: Optional[BaseForm] = ..., ) -> Union[Tuple[Optional[str], Union[Callable, Type[str]]], str]: ... def help_text_for_field(name: str, model: Type[Model]) -> str: ... -def display_for_field( - value: Any, field: Union[Field, reverse_related.OneToOneRel], empty_value_display: str -) -> str: ... +def display_for_field(value: Any, field: Field, empty_value_display: str) -> str: ... def display_for_value(value: Any, empty_value_display: str, boolean: bool = ...) -> str: ... class NotRelationField(Exception): ... def get_model_from_relation(field: Union[Field, reverse_related.ForeignObjectRel]) -> Type[Model]: ... def reverse_field_path(model: Type[Model], path: str) -> Tuple[Type[Model], str]: ... -def get_fields_from_path(model: Type[Model], path: str) -> List[Union[Field, FieldCacheMixin]]: ... +def get_fields_from_path(model: Type[Model], path: str) -> List[Field]: ... def construct_change_message( form: AdminPasswordChangeForm, formsets: None, add: bool ) -> List[Dict[str, Dict[str, List[str]]]]: ... diff --git a/django-stubs/contrib/auth/base_user.pyi b/django-stubs/contrib/auth/base_user.pyi index 10f7c24..c673938 100644 --- a/django-stubs/contrib/auth/base_user.pyi +++ b/django-stubs/contrib/auth/base_user.pyi @@ -13,11 +13,10 @@ class BaseUserManager(models.Manager[_T]): def get_by_natural_key(self, username: Optional[str]) -> _T: ... class AbstractBaseUser(models.Model): + REQUIRED_FIELDS: List[str] = ... + password = models.CharField(max_length=128) last_login = models.DateTimeField(blank=True, null=True) - - REQUIRED_FIELDS: List[str] = ... - class Meta: ... def get_username(self) -> str: ... def natural_key(self) -> Tuple[str]: ... @property diff --git a/django-stubs/contrib/auth/checks.pyi b/django-stubs/contrib/auth/checks.pyi index 9aeb20b..f2c5332 100644 --- a/django-stubs/contrib/auth/checks.pyi +++ b/django-stubs/contrib/auth/checks.pyi @@ -1,6 +1,8 @@ -from typing import Any, List +from typing import Any, List, Iterable, Optional from django.core.checks.messages import CheckMessage -def check_user_model(app_configs: None = ..., **kwargs: Any) -> List[CheckMessage]: ... -def check_models_permissions(app_configs: None = ..., **kwargs: Any) -> List[Any]: ... +from django.apps.config import AppConfig + +def check_user_model(app_configs: Optional[Iterable[AppConfig]] = ..., **kwargs: Any) -> List[CheckMessage]: ... +def check_models_permissions(app_configs: Optional[Iterable[AppConfig]] = ..., **kwargs: Any) -> List[Any]: ... diff --git a/django-stubs/contrib/contenttypes/checks.pyi b/django-stubs/contrib/contenttypes/checks.pyi index 9d1e3e2..97c17fa 100644 --- a/django-stubs/contrib/contenttypes/checks.pyi +++ b/django-stubs/contrib/contenttypes/checks.pyi @@ -1,4 +1,6 @@ -from typing import Any, List +from typing import Any, List, Iterable, Optional -def check_generic_foreign_keys(app_configs: None = ..., **kwargs: Any) -> List[Any]: ... -def check_model_name_lengths(app_configs: None = ..., **kwargs: Any) -> List[Any]: ... +from django.apps.config import AppConfig + +def check_generic_foreign_keys(app_configs: Optional[Iterable[AppConfig]] = ..., **kwargs: Any) -> List[Any]: ... +def check_model_name_lengths(app_configs: Optional[Iterable[AppConfig]] = ..., **kwargs: Any) -> List[Any]: ... diff --git a/django-stubs/contrib/sites/management.pyi b/django-stubs/contrib/sites/management.pyi index 175cbb4..822f479 100644 --- a/django-stubs/contrib/sites/management.pyi +++ b/django-stubs/contrib/sites/management.pyi @@ -1,10 +1,10 @@ from typing import Any +from django.apps.config import AppConfig from django.apps.registry import Apps -from django.contrib.sites.apps import SitesConfig def create_default_site( - app_config: SitesConfig, + app_config: AppConfig, verbosity: int = ..., interactive: bool = ..., using: str = ..., diff --git a/django-stubs/contrib/staticfiles/checks.pyi b/django-stubs/contrib/staticfiles/checks.pyi index 1ca1e96..dccf572 100644 --- a/django-stubs/contrib/staticfiles/checks.pyi +++ b/django-stubs/contrib/staticfiles/checks.pyi @@ -1,5 +1,7 @@ -from typing import Any, List +from typing import Any, List, Iterable, Optional from django.core.checks.messages import Error -def check_finders(app_configs: None = ..., **kwargs: Any) -> List[Error]: ... +from django.apps.config import AppConfig + +def check_finders(app_configs: Optional[Iterable[AppConfig]] = ..., **kwargs: Any) -> List[Error]: ... diff --git a/django-stubs/core/checks/caches.pyi b/django-stubs/core/checks/caches.pyi index 25250c4..94c8994 100644 --- a/django-stubs/core/checks/caches.pyi +++ b/django-stubs/core/checks/caches.pyi @@ -1,7 +1,9 @@ -from typing import Any, List +from typing import Any, List, Iterable, Optional from django.core.checks.messages import Error +from django.apps.config import AppConfig + E001: Any -def check_default_cache_is_configured(app_configs: None, **kwargs: Any) -> List[Error]: ... +def check_default_cache_is_configured(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Error]: ... diff --git a/django-stubs/core/checks/model_checks.pyi b/django-stubs/core/checks/model_checks.pyi index a424b11..ec877ce 100644 --- a/django-stubs/core/checks/model_checks.pyi +++ b/django-stubs/core/checks/model_checks.pyi @@ -1,6 +1,8 @@ -from typing import Any, List +from typing import Any, List, Iterable, Optional from django.core.checks.messages import Warning -def check_all_models(app_configs: None = ..., **kwargs: Any) -> List[Warning]: ... -def check_lazy_references(app_configs: None = ..., **kwargs: Any) -> List[Any]: ... +from django.apps.config import AppConfig + +def check_all_models(app_configs: Optional[Iterable[AppConfig]] = ..., **kwargs: Any) -> List[Warning]: ... +def check_lazy_references(app_configs: Optional[Iterable[AppConfig]] = ..., **kwargs: Any) -> List[Any]: ... diff --git a/django-stubs/core/checks/security/base.pyi b/django-stubs/core/checks/security/base.pyi index 0eeba15..7b67075 100644 --- a/django-stubs/core/checks/security/base.pyi +++ b/django-stubs/core/checks/security/base.pyi @@ -1,7 +1,9 @@ -from typing import Any, List +from typing import Any, List, Iterable, Optional from django.core.checks.messages import Warning +from django.apps.config import AppConfig + SECRET_KEY_MIN_LENGTH: int SECRET_KEY_MIN_UNIQUE_CHARACTERS: int W001: Any @@ -17,15 +19,15 @@ W019: Any W020: Any W021: Any -def check_security_middleware(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_xframe_options_middleware(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_sts(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_sts_include_subdomains(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_sts_preload(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_content_type_nosniff(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_xss_filter(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_ssl_redirect(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_secret_key(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_debug(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_xframe_deny(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_allowed_hosts(app_configs: None, **kwargs: Any) -> List[Warning]: ... +def check_security_middleware(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_xframe_options_middleware(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_sts(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_sts_include_subdomains(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_sts_preload(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_content_type_nosniff(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_xss_filter(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_ssl_redirect(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_secret_key(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_debug(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_xframe_deny(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_allowed_hosts(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... diff --git a/django-stubs/core/checks/security/csrf.pyi b/django-stubs/core/checks/security/csrf.pyi index 0ea56fb..94ca777 100644 --- a/django-stubs/core/checks/security/csrf.pyi +++ b/django-stubs/core/checks/security/csrf.pyi @@ -1,9 +1,11 @@ -from typing import Any, List +from typing import Any, List, Iterable, Optional from django.core.checks.messages import Warning +from django.apps.config import AppConfig + W003: Any W016: Any -def check_csrf_middleware(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_csrf_cookie_secure(app_configs: None, **kwargs: Any) -> List[Warning]: ... +def check_csrf_middleware(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_csrf_cookie_secure(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... diff --git a/django-stubs/core/checks/security/sessions.pyi b/django-stubs/core/checks/security/sessions.pyi index 9d6e294..c5f424f 100644 --- a/django-stubs/core/checks/security/sessions.pyi +++ b/django-stubs/core/checks/security/sessions.pyi @@ -1,7 +1,9 @@ -from typing import Any, List +from typing import Any, List, Iterable, Optional from django.core.checks.messages import Warning +from django.apps.config import AppConfig + def add_session_cookie_message(message: Any): ... W010: Any @@ -14,5 +16,5 @@ W013: Any W014: Any W015: Any -def check_session_cookie_secure(app_configs: None, **kwargs: Any) -> List[Warning]: ... -def check_session_cookie_httponly(app_configs: None, **kwargs: Any) -> List[Warning]: ... +def check_session_cookie_secure(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... +def check_session_cookie_httponly(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... diff --git a/django-stubs/core/checks/templates.pyi b/django-stubs/core/checks/templates.pyi index 4b35473..200db76 100644 --- a/django-stubs/core/checks/templates.pyi +++ b/django-stubs/core/checks/templates.pyi @@ -1,9 +1,11 @@ -from typing import Any, List +from typing import Any, List, Iterable, Optional from django.core.checks.messages import Error +from django.apps.config import AppConfig + E001: Any E002: Any -def check_setting_app_dirs_loaders(app_configs: None, **kwargs: Any) -> List[Error]: ... -def check_string_if_invalid_is_string(app_configs: None, **kwargs: Any) -> List[Error]: ... +def check_setting_app_dirs_loaders(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Error]: ... +def check_string_if_invalid_is_string(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Error]: ... diff --git a/django-stubs/core/checks/urls.pyi b/django-stubs/core/checks/urls.pyi index 1101a28..c9c43ee 100644 --- a/django-stubs/core/checks/urls.pyi +++ b/django-stubs/core/checks/urls.pyi @@ -1,11 +1,13 @@ -from typing import Any, Callable, List, Tuple, Union +from typing import Any, Callable, List, Tuple, Union, Iterable, Optional from django.core.checks.messages import CheckMessage, Error, Warning from django.urls.resolvers import URLPattern, URLResolver -def check_url_config(app_configs: None, **kwargs: Any) -> List[CheckMessage]: ... +from django.apps.config import AppConfig + +def check_url_config(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[CheckMessage]: ... def check_resolver(resolver: Union[Tuple[str, Callable], URLPattern, URLResolver]) -> List[CheckMessage]: ... -def check_url_namespaces_unique(app_configs: None, **kwargs: Any) -> List[Warning]: ... +def check_url_namespaces_unique(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Warning]: ... def get_warning_for_invalid_pattern(pattern: Any) -> List[Error]: ... -def check_url_settings(app_configs: None, **kwargs: Any) -> List[Error]: ... +def check_url_settings(app_configs: Optional[Iterable[AppConfig]], **kwargs: Any) -> List[Error]: ... def E006(name: str) -> Error: ... diff --git a/django-stubs/core/serializers/base.pyi b/django-stubs/core/serializers/base.pyi index 46e2e53..a910132 100644 --- a/django-stubs/core/serializers/base.pyi +++ b/django-stubs/core/serializers/base.pyi @@ -1,6 +1,6 @@ from datetime import date from io import BufferedReader, StringIO, TextIOWrapper -from typing import Any, Dict, Iterable, List, Mapping, Optional, Type, Union +from typing import Any, Dict, Iterable, List, Mapping, Optional, Type, Union, Collection from uuid import UUID from django.core.management.base import OutputWrapper @@ -35,18 +35,18 @@ class Serializer: internal_use_only: bool = ... progress_class: Any = ... stream_class: Any = ... - options: Any = ... + options: Dict[str, Any] = ... stream: Any = ... - selected_fields: Any = ... - use_natural_foreign_keys: Any = ... - use_natural_primary_keys: Any = ... + selected_fields: Optional[Collection[str]] = ... + use_natural_foreign_keys: bool = ... + use_natural_primary_keys: bool = ... first: bool = ... def serialize( self, queryset: Iterable[Model], *, stream: Optional[Any] = ..., - fields: Optional[Any] = ..., + fields: Optional[Collection[str]] = ..., use_natural_foreign_keys: bool = ..., use_natural_primary_keys: bool = ..., progress_output: Optional[Any] = ..., @@ -63,7 +63,7 @@ class Serializer: def getvalue(self) -> Optional[Union[bytes, str]]: ... class Deserializer: - options: Any = ... + options: Dict[str, Any] = ... stream: Any = ... def __init__(self, stream_or_string: Union[BufferedReader, TextIOWrapper, str], **options: Any) -> None: ... def __iter__(self) -> Deserializer: ... diff --git a/django-stubs/core/serializers/json.pyi b/django-stubs/core/serializers/json.pyi index 81e8a16..06c4769 100644 --- a/django-stubs/core/serializers/json.pyi +++ b/django-stubs/core/serializers/json.pyi @@ -1,24 +1,10 @@ import json -from datetime import datetime -from decimal import Decimal -from io import TextIOWrapper -from typing import Any, Union, Dict -from uuid import UUID +from typing import Any, Dict from django.core.serializers.python import Serializer as PythonSerializer -from django.db.models.base import Model class Serializer(PythonSerializer): json_kwargs: Dict[str, Any] - options: Dict[str, None] - selected_fields: None - stream: TextIOWrapper - use_natural_foreign_keys: bool - use_natural_primary_keys: bool - internal_use_only: bool = ... - def start_serialization(self) -> None: ... - def end_serialization(self) -> None: ... - def end_object(self, obj: Model) -> None: ... def Deserializer(stream_or_string: Any, **options: Any) -> None: ... @@ -29,4 +15,3 @@ class DjangoJSONEncoder(json.JSONEncoder): indent: int skipkeys: bool sort_keys: bool - def default(self, o: Union[datetime, Decimal, UUID]) -> str: ... diff --git a/django-stubs/core/serializers/python.pyi b/django-stubs/core/serializers/python.pyi index ed8eedd..a348e49 100644 --- a/django-stubs/core/serializers/python.pyi +++ b/django-stubs/core/serializers/python.pyi @@ -1,31 +1,15 @@ from collections import OrderedDict -from io import TextIOWrapper -from typing import Any, Dict, Iterator, List +from typing import Any, Dict, Iterator, List, Optional from django.core.serializers.base import DeserializedObject from django.db.models.base import Model -from django.db.models.fields.related import ForeignKey, ManyToManyField from django.core.serializers import base -from django.db.models.fields import Field class Serializer(base.Serializer): - options: Dict[Any, Any] - selected_fields: None - stream: TextIOWrapper - use_natural_foreign_keys: bool - use_natural_primary_keys: bool - internal_use_only: bool = ... objects: List[Any] = ... - def start_serialization(self) -> None: ... - def end_serialization(self) -> None: ... - def start_object(self, obj: Model) -> None: ... - def end_object(self, obj: Model) -> None: ... def get_dump_object(self, obj: Model) -> OrderedDict: ... - def handle_field(self, obj: Model, field: Field) -> None: ... - def handle_fk_field(self, obj: Model, field: ForeignKey) -> None: ... - def handle_m2m_field(self, obj: Model, field: ManyToManyField) -> None: ... def Deserializer( - object_list: List[Dict[str, Any]], *, using: Any = ..., ignorenonexistent: bool = ..., **options: Any + object_list: List[Dict[str, Any]], *, using: Optional[str] = ..., ignorenonexistent: bool = ..., **options: Any ) -> Iterator[DeserializedObject]: ... diff --git a/django-stubs/core/validators.pyi b/django-stubs/core/validators.pyi index d540bd1..34a7e48 100644 --- a/django-stubs/core/validators.pyi +++ b/django-stubs/core/validators.pyi @@ -1,15 +1,13 @@ -from datetime import datetime from decimal import Decimal from re import RegexFlag -from typing import Any, Dict, List, Optional, Union, Pattern, Collection -from uuid import UUID +from typing import Any, Dict, List, Optional, Union, Pattern, Collection, Callable, Tuple from django.core.files.base import File -from django.core.exceptions import ValidationError as ValidationError # noqa: F401 EMPTY_VALUES: Any _Regex = Union[str, Pattern[str]] +_ErrorMessage = Union[str, Any] def _lazy_re_compile(regex: _Regex, flags: int = ...): ... @@ -22,7 +20,7 @@ class RegexValidator: def __init__( self, regex: Optional[_Regex] = ..., - message: Optional[str] = ..., + message: Optional[_ErrorMessage] = ..., code: Optional[str] = ..., inverse_match: Optional[bool] = ..., flags: Optional[RegexFlag] = ..., @@ -45,67 +43,53 @@ integer_validator: Any def validate_integer(value: Optional[Union[float, str]]) -> None: ... class EmailValidator: - message: Any = ... + message: str = ... code: str = ... user_regex: Any = ... domain_regex: Any = ... literal_regex: Any = ... domain_whitelist: Any = ... def __init__( - self, message: Optional[str] = ..., code: Optional[str] = ..., whitelist: Optional[Collection[str]] = ... + self, + message: Optional[_ErrorMessage] = ..., + code: Optional[str] = ..., + whitelist: Optional[Collection[str]] = ..., ) -> None: ... def __call__(self, value: Optional[str]) -> None: ... def validate_domain_part(self, domain_part: str) -> bool: ... -validate_email: Any -slug_re: Any -validate_slug: Any -slug_unicode_re: Any -validate_unicode_slug: Any +validate_email: EmailValidator = ... +slug_re: Pattern = ... +validate_slug: RegexValidator = ... +slug_unicode_re: Pattern = ... +validate_unicode_slug: RegexValidator = ... def validate_ipv4_address(value: str) -> None: ... def validate_ipv6_address(value: str) -> None: ... def validate_ipv46_address(value: str) -> None: ... -ip_address_validator_map: Any +ip_address_validator_map: Dict[str, Tuple[Callable[[Any], None], str]] def ip_address_validators(protocol: str, unpack_ipv4: bool) -> Any: ... def int_list_validator( - sep: str = ..., message: None = ..., code: str = ..., allow_negative: bool = ... + sep: str = ..., message: Optional[_ErrorMessage] = ..., code: str = ..., allow_negative: bool = ... ) -> RegexValidator: ... validate_comma_separated_integer_list: Any class BaseValidator: - message: Any = ... + message: str = ... code: str = ... limit_value: Any = ... - def __init__(self, limit_value: Any, message: Optional[str] = ...) -> None: ... + def __init__(self, limit_value: Any, message: Optional[_ErrorMessage] = ...) -> None: ... def __call__(self, value: Any) -> None: ... - def compare(self, a: bool, b: bool) -> bool: ... + def compare(self, a: Any, b: Any) -> bool: ... def clean(self, x: Any) -> Any: ... -class MaxValueValidator(BaseValidator): - message: Any = ... - code: str = ... - def compare(self, a: Union[datetime, Decimal, float], b: Union[datetime, Decimal, float]) -> bool: ... - -class MinValueValidator(BaseValidator): - message: Any = ... - code: str = ... - def compare(self, a: Union[datetime, Decimal, float], b: Union[datetime, Decimal, float]) -> bool: ... - -class MinLengthValidator(BaseValidator): - message: Any = ... - code: str = ... - def compare(self, a: int, b: int) -> bool: ... - def clean(self, x: str) -> int: ... - -class MaxLengthValidator(BaseValidator): - message: Any = ... - code: str = ... - def compare(self, a: int, b: int) -> bool: ... - def clean(self, x: Union[bytes, str]) -> int: ... +class MaxValueValidator(BaseValidator): ... +class MinValueValidator(BaseValidator): ... +class MinLengthValidator(BaseValidator): ... +class MaxLengthValidator(BaseValidator): ... class DecimalValidator: messages: Any = ... @@ -115,13 +99,13 @@ class DecimalValidator: def __call__(self, value: Decimal) -> None: ... class FileExtensionValidator: - message: Any = ... + message: str = ... code: str = ... allowed_extensions: List[str] = ... def __init__( self, allowed_extensions: Optional[Collection[str]] = ..., - message: Optional[str] = ..., + message: Optional[_ErrorMessage] = ..., code: Optional[str] = ..., ) -> None: ... def __call__(self, value: File) -> None: ... @@ -130,7 +114,7 @@ def get_available_image_extensions() -> List[str]: ... def validate_image_file_extension(value: File) -> None: ... class ProhibitNullCharactersValidator: - message: Any = ... + message: str = ... code: str = ... - def __init__(self, message: Optional[str] = ..., code: Optional[str] = ...) -> None: ... - def __call__(self, value: Optional[Union[Dict[Any, Any], str, UUID]]) -> None: ... + def __init__(self, message: Optional[_ErrorMessage] = ..., code: Optional[str] = ...) -> None: ... + def __call__(self, value: Any) -> None: ... diff --git a/django-stubs/db/models/deletion.pyi b/django-stubs/db/models/deletion.pyi index 19c6a2b..6bc0069 100644 --- a/django-stubs/db/models/deletion.pyi +++ b/django-stubs/db/models/deletion.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Iterable, Optional, Union +from typing import Any, Callable, Iterable, Optional, Union, Collection, Type from django.db.models.base import Model @@ -18,4 +18,11 @@ class ProtectedError(IntegrityError): ... class Collector: def __init__(self, using: str) -> None: ... + def collect( + self, + objs: Collection[Optional[Model]], + source: Optional[Type[Model]] = ..., + source_attr: Optional[str] = ..., + **kwargs: Any + ) -> None: ... def can_fast_delete(self, objs: Union[Model, Iterable[Model]], from_field: Optional[Field] = ...) -> bool: ... diff --git a/django-stubs/db/models/query.pyi b/django-stubs/db/models/query.pyi index 59d910b..c2c3eb8 100644 --- a/django-stubs/db/models/query.pyi +++ b/django-stubs/db/models/query.pyi @@ -16,6 +16,7 @@ from typing import ( TypeVar, Union, overload, + Reversible, ) from django.db.models.base import Model @@ -121,13 +122,14 @@ class _BaseQuerySet(Generic[_T], Sized): def db(self) -> str: ... def resolve_expression(self, *args: Any, **kwargs: Any) -> Any: ... -class QuerySet(_BaseQuerySet[_T], Collection[_T], Sized): +class QuerySet(_BaseQuerySet[_T], Collection[_T], Reversible[_T], Sized): def __iter__(self) -> Iterator[_T]: ... def __contains__(self, x: object) -> bool: ... @overload def __getitem__(self, i: int) -> _T: ... @overload def __getitem__(self: _QS, s: slice) -> _QS: ... + def __reversed__(self) -> Iterator[_T]: ... _Row = TypeVar("_Row", covariant=True) diff --git a/django-stubs/http/request.pyi b/django-stubs/http/request.pyi index 1405c9e..c2c00bf 100644 --- a/django-stubs/http/request.pyi +++ b/django-stubs/http/request.pyi @@ -18,6 +18,7 @@ from typing import ( from django.contrib.auth.base_user import AbstractBaseUser from django.contrib.sessions.backends.base import SessionBase +from django.contrib.sites.models import Site from django.utils.datastructures import CaseInsensitiveMapping, ImmutableList, MultiValueDict from django.core.files import uploadedfile, uploadhandler @@ -51,6 +52,7 @@ class HttpRequest(BytesIO): content_type: Optional[str] = ... content_params: Optional[Dict[str, str]] = ... user: AbstractBaseUser + site: Site session: SessionBase encoding: Optional[str] = ... upload_handlers: UploadHandlerList = ... diff --git a/django-stubs/http/response.pyi b/django-stubs/http/response.pyi index 4c4b32e..813cd13 100644 --- a/django-stubs/http/response.pyi +++ b/django-stubs/http/response.pyi @@ -64,6 +64,7 @@ class HttpResponseBase(Iterable[Any]): class HttpResponse(HttpResponseBase): client: Client context: Context + content: Any csrf_cookie_set: bool redirect_chain: List[Tuple[str, int]] request: Dict[str, Any] @@ -78,10 +79,6 @@ class HttpResponse(HttpResponseBase): def __init__(self, content: object = ..., *args: Any, **kwargs: Any) -> None: ... def serialize(self) -> bytes: ... @property - def content(self) -> Any: ... - @content.setter - def content(self, value: Any) -> None: ... - @property def url(self) -> str: ... def json(self) -> Dict[str, Any]: ... @@ -107,7 +104,7 @@ class FileResponse(StreamingHttpResponse): def json(self) -> Dict[str, Any]: ... class HttpResponseRedirectBase(HttpResponse): - allowed_schemes = ... # type: List[str] + allowed_schemes: List[str] = ... def __init__(self, redirect_to: str, *args: Any, **kwargs: Any) -> None: ... class HttpResponseRedirect(HttpResponseRedirectBase): ... diff --git a/django-stubs/utils/encoding.pyi b/django-stubs/utils/encoding.pyi index 3d5c6d6..11fd059 100644 --- a/django-stubs/utils/encoding.pyi +++ b/django-stubs/utils/encoding.pyi @@ -13,28 +13,28 @@ _P = TypeVar("_P", bound=Promise) _S = TypeVar("_S", bound=str) _PT = TypeVar("_PT", None, int, float, Decimal, datetime.datetime, datetime.date, datetime.time) @overload -def smart_text(s: _P, encoding: str = ..., strings_only: bool = ..., errors: str = ...,) -> _P: ... +def smart_text(s: _P, encoding: str = ..., strings_only: bool = ..., errors: str = ...) -> _P: ... @overload -def smart_text(s: _PT, encoding: str = ..., strings_only: Literal[True] = ..., errors: str = ...,) -> _PT: ... +def smart_text(s: _PT, encoding: str = ..., strings_only: Literal[True] = ..., errors: str = ...) -> _PT: ... @overload def smart_text(s: _S, encoding: str = ..., strings_only: bool = ..., errors: str = ...) -> _S: ... @overload def smart_text(s: Any, encoding: str = ..., strings_only: bool = ..., errors: str = ...) -> str: ... def is_protected_type(obj: Any) -> bool: ... @overload -def force_text(s: _PT, encoding: str = ..., strings_only: Literal[True] = ..., errors: str = ...,) -> _PT: ... +def force_text(s: _PT, encoding: str = ..., strings_only: Literal[True] = ..., errors: str = ...) -> _PT: ... @overload def force_text(s: _S, encoding: str = ..., strings_only: bool = ..., errors: str = ...) -> _S: ... @overload def force_text(s: Any, encoding: str = ..., strings_only: bool = ..., errors: str = ...) -> str: ... @overload -def smart_bytes(s: _P, encoding: str = ..., strings_only: bool = ..., errors: str = ...,) -> _P: ... +def smart_bytes(s: _P, encoding: str = ..., strings_only: bool = ..., errors: str = ...) -> _P: ... @overload -def smart_bytes(s: _PT, encoding: str = ..., strings_only: Literal[True] = ..., errors: str = ...,) -> _PT: ... +def smart_bytes(s: _PT, encoding: str = ..., strings_only: Literal[True] = ..., errors: str = ...) -> _PT: ... @overload def smart_bytes(s: Any, encoding: str = ..., strings_only: bool = ..., errors: str = ...) -> bytes: ... @overload -def force_bytes(s: _PT, encoding: str = ..., strings_only: Literal[True] = ..., errors: str = ...,) -> _PT: ... +def force_bytes(s: _PT, encoding: str = ..., strings_only: Literal[True] = ..., errors: str = ...) -> _PT: ... @overload def force_bytes(s: Any, encoding: str = ..., strings_only: bool = ..., errors: str = ...) -> bytes: ... diff --git a/django-stubs/utils/tree.pyi b/django-stubs/utils/tree.pyi index 3f11e11..75a7c7b 100644 --- a/django-stubs/utils/tree.pyi +++ b/django-stubs/utils/tree.pyi @@ -10,7 +10,7 @@ class Node: connector: str = ... negated: bool = ... def __init__( - self, children: Optional[_NodeChildren] = ..., connector: Optional[str] = ..., negated: bool = ..., + self, children: Optional[_NodeChildren] = ..., connector: Optional[str] = ..., negated: bool = ... ) -> None: ... def __deepcopy__(self, memodict: Dict[Any, Any]) -> Node: ... def __len__(self) -> int: ... diff --git a/scripts/enabled_test_modules.py b/scripts/enabled_test_modules.py index 7fb01ad..4f47ece 100644 --- a/scripts/enabled_test_modules.py +++ b/scripts/enabled_test_modules.py @@ -4,13 +4,13 @@ import re IGNORED_MODULES = {'schema', 'gis_tests', 'admin_widgets', 'admin_filters', 'sitemaps_tests', 'staticfiles_tests', 'modeladmin', 'model_forms', - 'generic_views', 'forms_tests', 'flatpages_tests', 'admin_utils', + 'generic_views', 'forms_tests', 'flatpages_tests', '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'} + 'inline_formsets', 'foreign_object', 'cache'} -MOCK_OBJECTS = ['MockRequest', 'MockCompiler', 'modelz', 'call_count', 'call_args_list', +MOCK_OBJECTS = ['MockRequest', 'MockCompiler', 'MockModelAdmin', 'modelz', 'call_count', 'call_args_list', 'call_args', 'MockUser', 'Xtemplate', 'DummyRequest', 'DummyUser', 'MinimalUser', 'DummyNode'] EXTERNAL_MODULES = ['psycopg2', 'PIL', 'selenium', 'oracle', 'mysql', 'sqlparse', 'tblib', 'numpy', 'bcrypt', 'argon2', 'xml.dom'] @@ -67,6 +67,9 @@ IGNORED_ERRORS = { 'has no attribute "assert', 'Unsupported dynamic base class' ], + 'admin_utils': [ + '"Article" has no attribute "non_field"', + ], 'aggregation': [ re.compile(r'got "Optional\[(Author|Publisher)\]", expected "Union\[(Author|Publisher), Combinable\]"'), 'Argument 2 for "super" not an instance of argument 1', @@ -382,6 +385,9 @@ IGNORED_ERRORS = { 'expression has type "CurrentSiteManager[CustomArticle]", base class "AbstractArticle"', "Name 'Optional' is not defined", ], + 'sites_tests': [ + '"RequestSite" of "Union[Site, RequestSite]" has no attribute "id"', + ], 'syndication_tests': [ 'List or tuple expected as variable arguments' ],