Skip to content

Commit

Permalink
Changed from list to abstract Sequence type for http verbs (#415)
Browse files Browse the repository at this point in the history
* Changed from list to abstract Sequence type for http verbs

Allows method decorator to not fail on tuple, as there is no reason to
have `methods` mutable

* [pre-commit.ci] auto fixes from pre-commit.com hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
namper and pre-commit-ci[bot] committed May 13, 2023
1 parent 8b53c9b commit 667f31d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rest_framework-stubs/decorators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MethodMapper(dict):
def options(self, func: _View) -> _View: ...
def trace(self, func: _View) -> _View: ...

_LOWER_CASE_HTTP_VERBS: TypeAlias = list[
_LOWER_CASE_HTTP_VERBS: TypeAlias = Sequence[
Literal[
"get",
"post",
Expand All @@ -42,7 +42,7 @@ _LOWER_CASE_HTTP_VERBS: TypeAlias = list[
]
]

_MIXED_CASE_HTTP_VERBS: TypeAlias = list[
_MIXED_CASE_HTTP_VERBS: TypeAlias = Sequence[
Literal[
"GET",
"POST",
Expand Down
13 changes: 13 additions & 0 deletions tests/typecheck/test_decorators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,16 @@
permission_classes([IsAuthenticated & Permission])
permission_classes([IsAuthenticated | Permission])
permission_classes([~Permission])
- case: method_decorator
main: |
from rest_framework import viewsets
from rest_framework.decorators import action
class MyView(viewsets.ViewSet):
@action(methods=("get",), detail=False)
def view_func_1(request): ...
@action(methods=["post",], detail=False)
def view_func_2(request): ...

0 comments on commit 667f31d

Please sign in to comment.