diff --git a/django-stubs/shortcuts.pyi b/django-stubs/shortcuts.pyi index 05ab839..71b7b13 100644 --- a/django-stubs/shortcuts.pyi +++ b/django-stubs/shortcuts.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Dict, List, Optional, Type, Union +from typing import Any, Callable, Dict, List, Optional, Type, Union, Sequence from django.db.models import Manager, QuerySet from django.db.models.base import Model @@ -15,7 +15,7 @@ def render_to_response( ) -> HttpResponse: ... def render( request: HttpRequest, - template_name: str, + template_name: Union[str, Sequence[str]], context: Optional[Dict[str, Any]] = ..., content_type: Optional[str] = ..., status: Optional[int] = ..., diff --git a/django-stubs/utils/log.pyi b/django-stubs/utils/log.pyi index a4b2a22..2cda09d 100644 --- a/django-stubs/utils/log.pyi +++ b/django-stubs/utils/log.pyi @@ -1,25 +1,18 @@ import logging.config -from logging import LogRecord -from typing import Any, Callable, Dict, List, Optional, Union +from typing import Any, Callable, Dict, Optional from django.core.mail.backends.locmem import EmailBackend +from django.core.management.color import Style request_logger: Any DEFAULT_LOGGING: Any -def configure_logging( - logging_config: str, logging_settings: Dict[str, Union[Dict[str, Dict[str, Union[List[str], bool, str]]], int]] -) -> None: ... +def configure_logging(logging_config: str, logging_settings: Dict[str, Any]) -> None: ... class AdminEmailHandler(logging.Handler): - filters: List[django.utils.log.RequireDebugFalse] - formatter: None - level: int - lock: _thread.RLock include_html: bool = ... email_backend: Optional[str] = ... - def __init__(self, include_html: bool = ..., email_backend: None = ...) -> None: ... - def emit(self, record: LogRecord) -> None: ... + def __init__(self, include_html: bool = ..., email_backend: Optional[str] = ...) -> None: ... def send_mail(self, subject: str, message: str, *args: Any, **kwargs: Any) -> None: ... def connection(self) -> EmailBackend: ... def format_subject(self, subject: str) -> str: ... @@ -27,23 +20,14 @@ class AdminEmailHandler(logging.Handler): class CallbackFilter(logging.Filter): callback: Callable = ... def __init__(self, callback: Callable) -> None: ... - def filter(self, record: str) -> int: ... -class RequireDebugFalse(logging.Filter): - name: str - nlen: int - def filter(self, record: Union[LogRecord, str]) -> bool: ... - -class RequireDebugTrue(logging.Filter): - name: str - nlen: int - def filter(self, record: Union[LogRecord, str]) -> bool: ... +class RequireDebugFalse(logging.Filter): ... +class RequireDebugTrue(logging.Filter): ... class ServerFormatter(logging.Formatter): datefmt: None - style: django.core.management.color.Style = ... + style: Style = ... def __init__(self, *args: Any, **kwargs: Any) -> None: ... - def format(self, record: LogRecord) -> str: ... def uses_server_time(self) -> bool: ... def log_response( diff --git a/django-stubs/views/debug.pyi b/django-stubs/views/debug.pyi index a4c9b72..e3b8a92 100644 --- a/django-stubs/views/debug.pyi +++ b/django-stubs/views/debug.pyi @@ -1,4 +1,6 @@ +from importlib.abc import SourceLoader from typing import Any, Callable, Dict, List, Optional, Type, Union +from types import TracebackType from django.core.handlers.wsgi import WSGIRequest from django.http.request import QueryDict @@ -16,8 +18,8 @@ class CallableSettingWrapper: def cleanse_setting(key: Union[int, str], value: Any) -> Any: ... def get_safe_settings() -> Dict[str, Any]: ... def technical_500_response(request: Any, exc_type: Any, exc_value: Any, tb: Any, status_code: int = ...): ... -def get_default_exception_reporter_filter() -> SafeExceptionReporterFilter: ... -def get_exception_reporter_filter(request: Optional[WSGIRequest]) -> SafeExceptionReporterFilter: ... +def get_default_exception_reporter_filter() -> ExceptionReporterFilter: ... +def get_exception_reporter_filter(request: Optional[WSGIRequest]) -> ExceptionReporterFilter: ... class ExceptionReporterFilter: def get_post_parameters(self, request: Any): ... @@ -32,7 +34,7 @@ class SafeExceptionReporterFilter(ExceptionReporterFilter): class ExceptionReporter: request: Optional[WSGIRequest] = ... - filter: django.views.debug.SafeExceptionReporterFilter = ... + filter: ExceptionReporterFilter = ... exc_type: None = ... exc_value: Optional[str] = ... tb: None = ... @@ -41,12 +43,25 @@ class ExceptionReporter: template_does_not_exist: bool = ... postmortem: None = ... def __init__( - self, request: Optional[WSGIRequest], exc_type: None, exc_value: Optional[str], tb: None, is_email: bool = ... + self, + request: Optional[WSGIRequest], + exc_type: Optional[Type[BaseException]], + exc_value: Optional[Union[str, BaseException]], + tb: Optional[TracebackType], + is_email: bool = ..., ) -> None: ... def get_traceback_data(self) -> Dict[str, Any]: ... def get_traceback_html(self) -> SafeText: ... def get_traceback_text(self) -> SafeText: ... def get_traceback_frames(self) -> List[Any]: ... + def _get_lines_from_file( + self, + filename: str, + lineno: int, + context_lines: int, + loader: Optional[SourceLoader] = ..., + module_name: Optional[str] = None, + ): ... def technical_404_response(request: WSGIRequest, exception: Http404) -> HttpResponse: ... def default_urlconf(request: WSGIRequest) -> HttpResponse: ... diff --git a/django-stubs/views/static.pyi b/django-stubs/views/static.pyi index b51daae..e75fc1d 100644 --- a/django-stubs/views/static.pyi +++ b/django-stubs/views/static.pyi @@ -9,4 +9,4 @@ DEFAULT_DIRECTORY_INDEX_TEMPLATE: str template_translatable: Any def directory_index(path: Any, fullpath: Any): ... -def was_modified_since(header: None = ..., mtime: float = ..., size: int = ...) -> bool: ... +def was_modified_since(header: Optional[str] = ..., mtime: float = ..., size: int = ...) -> bool: ... diff --git a/scripts/typecheck_tests.py b/scripts/typecheck_tests.py index ffad2a5..e3098bf 100644 --- a/scripts/typecheck_tests.py +++ b/scripts/typecheck_tests.py @@ -125,6 +125,10 @@ IGNORED_ERRORS = { ], 'select_related_onetoone': [ '"None" has no attribute' + ], + 'view_tests': [ + '"Handler" has no attribute "include_html"', + '"EmailMessage" has no attribute "alternatives"' ] } # Test folders to typecheck @@ -330,7 +334,7 @@ TESTS_DIRS = [ # TODO: 'validation', 'validators', 'version', - # TODO: 'view_tests', + 'view_tests', # TODO: 'wsgi', ]