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.
What's wrong
rest_framework.request.Request.parser_context
is typed as possibly beingNone
. However according to the constructor of theRequest
class it can never actually beNone
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 thandict[str, Any] | None
.System information
python
version: 3.11.5django
version: 4.2mypy
version: 1.5django-stubs
version: 3.14.2