Closed mgraczyk closed 11 months ago
Sorry the param type is not quite right. I will fix it.
Ok I think this works:
class _HttpRequestBuilder(Protocol, HttpRequest): ...
Not 100% sure that this is right though, open to suggestions. I'm trying to express "this is a function that takes the same arguments as the HttpRequest init method"
Hi, thanks for contributing!
Unfortunately you can't do class _HttpRequestBuilder(Protocol, HttpRequest): ...
because protocols are forbidden from inheriting from normal classes: https://peps.python.org/pep-0544/#protocols-subclassing-normal-classes
I think the best solution might be to define a callable protocol with a signature that matches the HttpRequest
initializer, i.e. something like:
class _HttpRequestBuilder(Protocol):
def __call__(self, ...) -> HttpRequest: ...
where you replace the first ...
with the parameter list of HttpRequest.__init__
. Unfortunately I haven't written the actual types for that one: https://github.com/henribru/google-api-python-client-stubs/blob/master/googleapiclient-stubs/http.pyi#L93-L103 So if you want an accurate signature for the request builder you'll have to figure out those types first and then copy that signature
requestBuilder can take any function that returns an HttpRequest