Skip to content

Request.parser_context is typed as possibly None while it never can be None #473

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

Closed
PureTryOut opened this issue Sep 26, 2023 · 0 comments · Fixed by #476
Closed

Request.parser_context is typed as possibly None while it never can be None #473

PureTryOut opened this issue Sep 26, 2023 · 0 comments · Fixed by #476
Labels
bug Something isn't working

Comments

@PureTryOut
Copy link

What's wrong

rest_framework.request.Request.parser_context is typed as possibly being None. However according to the constructor of the Request class it can never actually be None because if it is it would be set to an empty dict instead, see https://github.com/encode/django-rest-framework/blob/master/rest_framework/request.py#L171.
Due to this wrong typing I now either have to code for an impossible scenario or disable a mypy rule, both I rather not do.

How is that should be

It should be typed as just dict[str, Any] rather than dict[str, Any] | None.

System information

  • OS: Alpine Linux
  • python version: 3.11.5
  • django version: 4.2
  • mypy version: 1.5
  • django-stubs version: 3.14.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

1 participant