You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of a recent django-stubs release, and HttpResponseRedirect and HttpResponsePermanentRedirect are no longer compatible with each other (rightly so, they only share an ancestor but the latter does not inherit from the former).
This means to annotate a view's response, you need to use something like Union[TemplateResponse, HttpResponseRedirect, HttpResponsePermanentRedirect] for your typical https://en.wikipedia.org/wiki/Post/Redirect/Get . Obviously you could just annotate with HttpResponse but I would argue that's too weak.
Happy to take a stab at this assuming we're ok with using newer MyPy features like that above. I'm not quite sure if we should import Literal from typing or from somewhere else if we support lower Python versions. Any guidance on these imports would be great.
Thanks for all the work on this library. It's really improved my Mypy experience.
System information
OS:
python version: 3.8
django version: 3.0
mypy version: 0.770
django-stubs version: 1.5.0
The text was updated successfully, but these errors were encountered:
1.2 had redirect returning HttpResponseRedirectonly. In reality, this was incorrect as we know it can return HttpResponsePermanentRedirect too. See here:
To be clear, it's not a bug per se. I think the issue just defaulted to bug. This is really more of an improvement to redirect. Apologies if I messed it up on my end.
Uh oh!
There was an error while loading. Please reload this page.
Bug report
What's wrong
As of a recent
django-stubs
release, andHttpResponseRedirect
andHttpResponsePermanentRedirect
are no longer compatible with each other (rightly so, they only share an ancestor but the latter does not inherit from the former).This means to annotate a view's response, you need to use something like
Union[TemplateResponse, HttpResponseRedirect, HttpResponsePermanentRedirect]
for your typical https://en.wikipedia.org/wiki/Post/Redirect/Get . Obviously you could just annotate withHttpResponse
but I would argue that's too weak.How is that should be
Calling redirect with
permanent=True
should return one type, andpermanent=False
return another. This is possible withLiteral
types now, see https://mypy.readthedocs.io/en/stable/literal_types.html.Happy to take a stab at this assuming we're ok with using newer MyPy features like that above. I'm not quite sure if we should import Literal from
typing
or from somewhere else if we support lower Python versions. Any guidance on these imports would be great.Thanks for all the work on this library. It's really improved my Mypy experience.
System information
python
version: 3.8django
version: 3.0mypy
version: 0.770django-stubs
version: 1.5.0The text was updated successfully, but these errors were encountered: