From 2a1c86744cb4fc6a401a0923c6b48f271403c495 Mon Sep 17 00:00:00 2001 From: Thomas Krapp Date: Sat, 1 May 2021 12:42:29 +0200 Subject: [PATCH] Update decorators.pyi to match Django 3.1 (#576) * Update decorators.pyi to match Django 3.1 This commit resembles the state of the file in Django 3.1. Unfortunately, this is not even compatible with Django 3.0 which misses the sync* and async* decorators. * Update decorators.pyi * Fixes lint Co-authored-by: Nikita Sobolev --- django-stubs/core/management/base.pyi | 2 +- django-stubs/db/models/query.pyi | 4 +++- django-stubs/utils/decorators.pyi | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/django-stubs/core/management/base.pyi b/django-stubs/core/management/base.pyi index 5ec61d9..3e43642 100644 --- a/django-stubs/core/management/base.pyi +++ b/django-stubs/core/management/base.pyi @@ -39,7 +39,7 @@ class BaseCommand: help: str = ... output_transaction: bool = ... requires_migrations_checks: bool = ... - requires_system_checks: Union[bool, List[Tags], Tuple[Tags, ...], str] = ... + requires_system_checks: Union[bool, List[Tags], Tuple[Tags, ...], str] = ... base_stealth_options: Tuple[str, ...] = ... stealth_options: Tuple[str, ...] = ... stdout: OutputWrapper = ... diff --git a/django-stubs/db/models/query.pyi b/django-stubs/db/models/query.pyi index 9a15325..6d476c2 100644 --- a/django-stubs/db/models/query.pyi +++ b/django-stubs/db/models/query.pyi @@ -96,7 +96,9 @@ class _BaseQuerySet(Generic[_T], Sized): def union(self: _QS, *other_qs: Any, all: bool = ...) -> _QS: ... def intersection(self: _QS, *other_qs: Any) -> _QS: ... def difference(self: _QS, *other_qs: Any) -> _QS: ... - def select_for_update(self: _QS, nowait: bool = ..., skip_locked: bool = ..., of: Sequence[str] = ..., no_key: bool = ...) -> _QS: ... + def select_for_update( + self: _QS, nowait: bool = ..., skip_locked: bool = ..., of: Sequence[str] = ..., no_key: bool = ... + ) -> _QS: ... def select_related(self: _QS, *fields: Any) -> _QS: ... def prefetch_related(self: _QS, *lookups: Any) -> _QS: ... # TODO: return type diff --git a/django-stubs/utils/decorators.pyi b/django-stubs/utils/decorators.pyi index 704213d..e58530a 100644 --- a/django-stubs/utils/decorators.pyi +++ b/django-stubs/utils/decorators.pyi @@ -6,11 +6,14 @@ from django.views.generic.base import View from django.utils.functional import classproperty as classproperty _T = TypeVar("_T", bound=Union[View, Callable]) # Any callable +_CallableType = TypeVar("_CallableType", bound=Callable) class classonlymethod(classmethod): ... def method_decorator(decorator: Union[Callable, Iterable[Callable]], name: str = ...) -> Callable[[_T], _T]: ... def decorator_from_middleware_with_args(middleware_class: type) -> Callable: ... def decorator_from_middleware(middleware_class: type) -> Callable: ... -def available_attrs(fn: Callable): ... def make_middleware_decorator(middleware_class: Type[MiddlewareMixin]) -> Callable: ... +def sync_and_async_middleware(func: _CallableType) -> _CallableType: ... +def sync_only_middleware(func: _CallableType) -> _CallableType: ... +def async_only_middleware(func: _CallableType) -> _CallableType: ...