Skip to content

Commit

Permalink
Merge branch 'master' into ruff-lints-part1
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr authored Dec 5, 2023
2 parents a7ca882 + 857df7c commit 1e693ad
Show file tree
Hide file tree
Showing 23 changed files with 308 additions and 286 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_language_version:
python: python3.12
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: trailing-whitespace
Expand All @@ -13,12 +13,12 @@ repos:
- id: check-merge-conflict
- id: end-of-file-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.1.6
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix"]
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.11.0
hooks:
- id: black

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
wheel
pre-commit==3.5.0
pytest==7.4.2
pytest==7.4.3
pytest-mypy-plugins==3.0.0
djangorestframework==3.14.0
types-pytz==2023.3.1.1
types-requests==2.31.0.10
types-urllib3==1.26.25.14
git+https://github.com/typeddjango/django-stubs
git+https://github.com/typeddjango/django-stubs#subdirectory=ext
django-stubs[compatible-mypy] @ git+https://github.com/typeddjango/django-stubs
django-stubs-ext @ git+https://github.com/typeddjango/django-stubs#subdirectory=ext
-e .[compatible-mypy,coreapi,markdown]
9 changes: 7 additions & 2 deletions rest_framework-stubs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
__title__: str
__version__: str
__author__: str
__license__: str
__copyright__: str

VERSION: str
HTTP_HEADER_ENCODING: str
ISO_8601: str
default_app_config: str

class RemovedInDRF313Warning(DeprecationWarning): ...
class RemovedInDRF314Warning(PendingDeprecationWarning): ...
class RemovedInDRF315Warning(PendingDeprecationWarning): ...
2 changes: 2 additions & 0 deletions rest_framework-stubs/authtoken/admin.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.contrib import admin
from django.contrib.admin.views.main import ChangeList

class TokenChangeList(ChangeList): ...
class TokenAdmin(admin.ModelAdmin): ...
2 changes: 2 additions & 0 deletions rest_framework-stubs/authtoken/views.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ from rest_framework.views import APIView, AsView, GenericView
class ObtainAuthToken(APIView):
serializer_class: type[Serializer]
def post(self, request: Request, *args: Any, **kwargs: Any) -> Response: ...
def get_serializer_context(self) -> dict[str, Any]: ...
def get_serializer(self, *args: Any, **kwargs: Any) -> Serializer: ...

obtain_auth_token: AsView[GenericView]
63 changes: 27 additions & 36 deletions rest_framework-stubs/decorators.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from collections.abc import Callable, Mapping, Sequence
from typing import Any, Literal, Protocol, TypeVar

Expand All @@ -17,6 +18,31 @@ _View = TypeVar("_View", bound=Callable[..., HttpResponseBase])
_P = ParamSpec("_P")
_RESP = TypeVar("_RESP", bound=HttpResponseBase)

_MixedCaseHttpMethod: TypeAlias = Literal[
"GET",
"POST",
"DELETE",
"PUT",
"PATCH",
"TRACE",
"HEAD",
"OPTIONS",
"get",
"post",
"delete",
"put",
"patch",
"trace",
"head",
"options",
]
if sys.version_info >= (3, 11):
from http import HTTPMethod

_HttpMethod: TypeAlias = _MixedCaseHttpMethod | HTTPMethod
else:
_HttpMethod: TypeAlias = _MixedCaseHttpMethod

class MethodMapper(dict):
def __init__(self, action: _View, methods: Sequence[str]) -> None: ...
def _map(self, method: str, func: _View) -> _View: ...
Expand All @@ -29,43 +55,8 @@ class MethodMapper(dict):
def options(self, func: _View) -> _View: ...
def trace(self, func: _View) -> _View: ...

_LOWER_CASE_HTTP_VERBS: TypeAlias = Sequence[
Literal[
"get",
"post",
"delete",
"put",
"patch",
"trace",
"head",
"options",
]
]

_MIXED_CASE_HTTP_VERBS: TypeAlias = Sequence[
Literal[
"GET",
"POST",
"DELETE",
"PUT",
"PATCH",
"TRACE",
"HEAD",
"OPTIONS",
"get",
"post",
"delete",
"put",
"patch",
"trace",
"head",
"options",
]
]

class ViewSetAction(Protocol[_View]):
detail: bool
methods: _LOWER_CASE_HTTP_VERBS
url_path: str
url_name: str
kwargs: Mapping[str, Any]
Expand All @@ -84,7 +75,7 @@ def throttle_classes(throttle_classes: Sequence[BaseThrottle | type[BaseThrottle
def permission_classes(permission_classes: Sequence[_PermissionClass]) -> Callable[[_View], _View]: ...
def schema(view_inspector: ViewInspector | type[ViewInspector] | None) -> Callable[[_View], _View]: ...
def action(
methods: _MIXED_CASE_HTTP_VERBS | None = ...,
methods: Sequence[_HttpMethod] | None = ...,
detail: bool = ...,
url_path: str | None = ...,
url_name: str | None = ...,
Expand Down
Loading

0 comments on commit 1e693ad

Please sign in to comment.