Python 3.11, support new http.HTTPMethod enum in action and view · Issue #8995 · encode/django-rest-framework (original) (raw)

Bug report

When using python 3.11, instead of hardcoding HTTP verbs, now we can use official enum: HTTPMethod as well as HTTPStatus for statuses

What's wrong

We would like to use it in decorators.action(methods=[HTTPMethod.POST]) for instance.
Currently it does not work and produce the following error (with djangorestframework-stubs package):

error: List item 0 has incompatible type "Literal[HTTPMethod.POST]"; expected "Literal['GET', 'POST', 'DELETE', 'PUT', 'PATCH', 'TRACE', 'HEAD', 'OPTIONS', 'get', 'post', 'delete', 'put', 'patch', 'trace', 'head', 'options']" [list-item]

How is that should be

No mypy error should be reported

System information

Original issue:

The issue was originally reported against the stub project, but recommended to move the issue/discussion over here: typeddjango/djangorestframework-stubs#396