Skip to content

Python 3.11, support new http.HTTPMethod enum in action and view #8995

Closed
@sshishov

Description

@sshishov

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

  • OS: MacOS / Debian (docker)
  • python version: 3.11
  • django version: 3.2.18
  • mypy version: 1.2.0
  • django-stubs version: 1.16.0
  • djangorestframework-stubs version: 1.10.0

Original issue:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions