-
-
Notifications
You must be signed in to change notification settings - Fork 527
only allow redirect_chain attribute in response when client sets the follow flag
#1257
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ | |
| reveal_type(response.client) # N: Revealed type is "django.test.client.Client" | ||
| reveal_type(response.context) # N: Revealed type is "Union[django.test.utils.ContextList, builtins.dict[builtins.str, Any]]" | ||
| reveal_type(response.content) # N: Revealed type is "builtins.bytes" | ||
| reveal_type(response.redirect_chain) # N: Revealed type is "builtins.list[Tuple[builtins.str, builtins.int]]" | ||
| response.json() | ||
| - case: async_client_methods | ||
| main: | | ||
|
|
@@ -35,3 +34,76 @@ | |
| async_factory = AsyncRequestFactory() | ||
| async_request = async_factory.get('foo') | ||
| reveal_type(async_request) # N: Revealed type is "django.core.handlers.asgi.ASGIRequest" | ||
| - case: client_follow_flag | ||
| main: | | ||
| from django.test.client import Client | ||
| client = Client() | ||
| response = client.get('foo') | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.get('foo', follow=False) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.get('foo', follow=True) | ||
| reveal_type(response.redirect_chain) # N: Revealed type is "builtins.list[Tuple[builtins.str, builtins.int]]" | ||
| x: bool | ||
| response = client.get('foo', follow=x) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.post('foo') | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.post('foo', follow=False) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.post('foo', follow=True) | ||
| reveal_type(response.redirect_chain) # N: Revealed type is "builtins.list[Tuple[builtins.str, builtins.int]]" | ||
| x: bool | ||
| response = client.post('foo', follow=x) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.head('foo') | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.head('foo', follow=False) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.head('foo', follow=True) | ||
| reveal_type(response.redirect_chain) # N: Revealed type is "builtins.list[Tuple[builtins.str, builtins.int]]" | ||
| x: bool | ||
| response = client.head('foo', follow=x) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.trace('foo') | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.trace('foo', follow=False) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.trace('foo', follow=True) | ||
| reveal_type(response.redirect_chain) # N: Revealed type is "builtins.list[Tuple[builtins.str, builtins.int]]" | ||
| x: bool | ||
| response = client.trace('foo', follow=x) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.put('foo') | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.put('foo', follow=False) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.put('foo', follow=True) | ||
| reveal_type(response.redirect_chain) # N: Revealed type is "builtins.list[Tuple[builtins.str, builtins.int]]" | ||
| x: bool | ||
| response = client.put('foo', follow=x) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.patch('foo') | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.patch('foo', follow=False) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.patch('foo', follow=True) | ||
| reveal_type(response.redirect_chain) # N: Revealed type is "builtins.list[Tuple[builtins.str, builtins.int]]" | ||
| x: bool | ||
| response = client.patch('foo', follow=x) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.delete('foo') | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.delete('foo', follow=False) | ||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
| response = client.delete('foo', follow=True) | ||
| reveal_type(response.redirect_chain) # N: Revealed type is "builtins.list[Tuple[builtins.str, builtins.int]]" | ||
| x: bool | ||
| response = client.delete('foo', follow=x) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should allow
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sobolevn sorry, I cannot follow you. Or do you mean "not allow
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry :( I mean that using Is it better now? 😊 |
||
| response.redirect_chain # E: "_MonkeyPatchedWSGIResponse" has no attribute "redirect_chain" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this overload, it is the same as
boolUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sobolevn this will cause a false positive tho for the default value, e.g.
Client().get('foo').response_chainwill be inferred as existing since thefollow: Literal[True]case matches and I can't put it behind the broaderfollow: boolcase. Theclient_follow_flagtest I added should also fail when the first override is deleted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Ordinarily you would remove the default value (
= ...) from the argument in one of the overloads, likeBut here it's not allowed because it follows another argument with default
data.I'm not aware of any tricks to make it work. May indeed have to use 3 overloads.