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
Httpsession requests typing #2699
base: master
Are you sure you want to change the base?
Conversation
…r type annotations support
This PR is still not finished (in draft). Requires adding similar annotations to FastHttpSession and more testing. |
I’ll have a look! |
Is it possible to put all the override definitions in a if typing_checking-block as well? I'd like to avoid the extra level of indirection at run time. |
I'm not 100% sure, but according to my current understanding of Python typing ecosystem — no.
What is the main reason behind it? Source code of methods in the base class is very short: def get(self, url, **kwargs):
kwargs.setdefault("allow_redirects", True)
return self.request("GET", url, **kwargs)
def options(self, url, **kwargs):
kwargs.setdefault("allow_redirects", True)
return self.request("OPTIONS", url, **kwargs)
def head(self, url, **kwargs):
kwargs.setdefault("allow_redirects", False)
return self.request("HEAD", url, **kwargs)
def post(self, url, data=None, json=None, **kwargs):
return self.request("POST", url, data=data, json=json, **kwargs)
def put(self, url, data=None, **kwargs):
return self.request("PUT", url, data=data, **kwargs)
def patch(self, url, data=None, **kwargs):
return self.request("PATCH", url, data=data, **kwargs)
def delete(self, url, **kwargs):
return self.request("DELETE", url, **kwargs) What do you think about following possible implementation in Locust: def get(self, url: str | bytes, **kwargs: Unpack[RESTKwargs]): # type: ignore[override]
kwargs.setdefault("allow_redirects", True)
return self.request("GET", url, **kwargs) # type: ignore[misc] The number of function call would remain the same. |
Yes, I’m mostly thinking about runtime performance. Why doesnt it work to define the wrappers in an if-block? |
I think about it as defining types of method that de facto doesn't exist (in contrast to a function with the same name in a base class). |
The aim of this PR is to provide better typing annotation support for
class HttpSession
.This should also fix #2563.