Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sshishov opened this issue Apr 18, 2023 · 5 comments · Fixed by #512
Closed

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

sshishov opened this issue Apr 18, 2023 · 5 comments · Fixed by #512
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@sshishov
Copy link
Contributor

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:

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
@sshishov sshishov added the bug Something isn't working label Apr 18, 2023
@intgr intgr self-assigned this Apr 19, 2023
@intgr
Copy link
Contributor

intgr commented Apr 19, 2023

I'm unsure about this.

While StrEnums like HTTPMethod.POST try to behave similar to the string "POST", and indeed it's even subclassing str, I'm afraid there can be subtle differences in behavior. It could trip some edge case in DRF code and lead to different behavior.

As far as I can tell, there are no unit tests in DRF that use HTTPMethod, nor are there any examples in documentation.

I would be comfortable with allowing this when we have some commitment from DRF upstream that this will be supported going forward, preferably in the form of tests or documentation examples.

So maybe open an issue with DRF upstream and see what they think.

@intgr intgr added enhancement New feature or request and removed bug Something isn't working labels Apr 19, 2023
@sshishov
Copy link
Contributor Author

Thank you @intgr , going to create the ticket on DRF itself, if they will be willing to support this standard library enums

@sshishov
Copy link
Contributor Author

sshishov commented Nov 8, 2023

Hello @intgr , the parent issue has been fixed and merged? Can we do something here also to go forward?

@intgr
Copy link
Contributor

intgr commented Nov 8, 2023

Yes, are you interested in creating a pull request?

@sshishov
Copy link
Contributor Author

sshishov commented Nov 9, 2023

I can try to do it @intgr , will do it in close future. Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Development

Successfully merging a pull request may close this issue.

2 participants