Fix return type for django.shortcuts.render #1140
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The return type for calling
shorcuts.render
without providing a value for thepermanent
kwarg wasHttpResponsePermanentRedirect
, while it should beHttpResponseRedirect
.The reason is that the first two overloads of the type stub overlap for the case of using the default argument. While
mypy
does issue an error for this, it was previously ignored with the# type: ignore
comment.As the first overload annotates the function as having the return type
HttpResponsePermanentRedirect
, this overlap would cause mypy to assume that the return type isHttpResponsePermanentRedirect
instead of the actual return typeHttpResponseRedirect
.Since calling
django.shortcuts.redirect
without providing an argument forpermanent
is the same as calling it with aLiteral[False]
(as the default value is aFalse
), we can improve the stub by only specifying the option to use the default argument (= ...
) in the second overload.This also removes the overlap in stub definitions, meaning that the
# type: ignore
can also be removed.Related issues
shortcuts.redirect
if using the default argument forpermanent
in the call #1138