|
1 | 1 | from collections.abc import Callable, Mapping, Sequence
|
| 2 | +from http import HTTPMethod |
2 | 3 | from typing import Any, Literal, Protocol, TypeVar
|
3 | 4 |
|
4 | 5 | from django.http import HttpRequest
|
@@ -29,43 +30,24 @@ class MethodMapper(dict):
|
29 | 30 | def options(self, func: _View) -> _View: ...
|
30 | 31 | def trace(self, func: _View) -> _View: ...
|
31 | 32 |
|
32 |
| -_LOWER_CASE_HTTP_VERBS: TypeAlias = Sequence[ |
33 |
| - Literal[ |
34 |
| - "get", |
35 |
| - "post", |
36 |
| - "delete", |
37 |
| - "put", |
38 |
| - "patch", |
39 |
| - "trace", |
40 |
| - "head", |
41 |
| - "options", |
42 |
| - ] |
43 |
| -] |
44 |
| - |
45 | 33 | _MIXED_CASE_HTTP_VERBS: TypeAlias = Sequence[
|
| 34 | + # fmt: off |
46 | 35 | Literal[
|
47 |
| - "GET", |
48 |
| - "POST", |
49 |
| - "DELETE", |
50 |
| - "PUT", |
51 |
| - "PATCH", |
52 |
| - "TRACE", |
53 |
| - "HEAD", |
54 |
| - "OPTIONS", |
55 |
| - "get", |
56 |
| - "post", |
57 |
| - "delete", |
58 |
| - "put", |
59 |
| - "patch", |
60 |
| - "trace", |
61 |
| - "head", |
62 |
| - "options", |
| 36 | + "get" , "GET" , HTTPMethod.GET , |
| 37 | + "post" , "POST" , HTTPMethod.POST , |
| 38 | + "delete" , "DELETE" , HTTPMethod.DELETE , |
| 39 | + "put" , "PUT" , HTTPMethod.PUT , |
| 40 | + "patch" , "PATCH" , HTTPMethod.PATCH , |
| 41 | + "trace" , "TRACE" , HTTPMethod.TRACE , |
| 42 | + "head" , "HEAD" , HTTPMethod.HEAD , |
| 43 | + "options", "OPTIONS", HTTPMethod.OPTIONS, |
63 | 44 | ]
|
| 45 | + # fmt: on |
64 | 46 | ]
|
65 | 47 |
|
66 | 48 | class ViewSetAction(Protocol[_View]):
|
67 | 49 | detail: bool
|
68 |
| - methods: _LOWER_CASE_HTTP_VERBS |
| 50 | + methods: _MIXED_CASE_HTTP_VERBS |
69 | 51 | url_path: str
|
70 | 52 | url_name: str
|
71 | 53 | kwargs: Mapping[str, Any]
|
|
0 commit comments