typeddjango / djangorestframework-stubs

PEP-484 stubs for django-rest-framework
MIT License
453 stars 117 forks source link

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

Closed PureTryOut closed 1 year ago

PureTryOut commented 1 year ago

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