-
-
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?
only allow redirect_chain attribute in response when client sets the follow flag
#1257
Conversation
…follow flag Signed-off-by: Oleg Hoefling <[email protected]>
sobolevn
left a comment
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.
The same is for all other overloads.
Do you agree?
| def request(self, **request: Any) -> _MonkeyPatchedWSGIResponse: ... | ||
| def get( # type: ignore | ||
| @overload # type: ignore | ||
| def get( |
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 bool
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_chain will be inferred as existing since the follow: Literal[True] case matches and I can't put it behind the broader follow: bool case. The client_follow_flag test 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, like
@overload
def get(self, path: str, data: Any = ..., follow: Literal[True], secure: bool = ..., **extra: Any) -> _MonkeyPatchedWSGIResponseRedirect: ...
# ^^^^^^^^^^^^^^^^^^^^^
@overload
def get(self, path: str, data: Any = ..., follow: bool = ..., secure: bool = ..., **extra: Any) -> _MonkeyPatchedWSGIResponse: ...But 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.
Signed-off-by: Oleg Hoefling <[email protected]>
Signed-off-by: Oleg Hoefling <[email protected]>
| 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) |
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.
Maybe we should allow bool? I think the main usecase for this is in unit-tests. They will be checked in all cases, but we can just make things harder for users by producing errors (and possibly false-positives).
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 sorry, I cannot follow you. Or do you mean "not allow bool" instead? Only boolean literals?
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.
Sorry :(
I mean that using bool should not produce this error. Because users will get a unittest failure if it is not True anyway. And I don't want to have false-positives in test code.
Is it better now? 😊
Signed-off-by: Oleg Hoefling [email protected]
I have made things!
This is #1252, reintroduced. Description copied for the sake of completeness:
The
redirect_chainattribute was added in #1124. At runtime, the response only has this attribute set when the request was made withfollow=True:This PR replicates this behaviour.
Related issues
Refs #1252