Skip to content

Commit

Permalink
Add more types to _http_client.py (#1169)
Browse files Browse the repository at this point in the history
* Add some types to _http_client

* better rename
  • Loading branch information
richardm-stripe authored Dec 11, 2023
1 parent b9d4efa commit 387a5da
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions stripe/_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

try:
import requests
from requests import Session
except ImportError:
requests = None
else:
Expand Down Expand Up @@ -314,8 +315,16 @@ def close(self):
class RequestsClient(HTTPClient):
name = "requests"

def __init__(self, timeout=80, session=None, **kwargs):
super(RequestsClient, self).__init__(**kwargs)
def __init__(
self,
timeout: int = 80,
session: Optional["Session"] = None,
verify_ssl_certs: bool = True,
proxy: Optional[Union[str, HTTPClient._Proxy]] = None,
):
super(RequestsClient, self).__init__(
verify_ssl_certs=verify_ssl_certs, proxy=proxy
)
self._session = session
self._timeout = timeout

Expand Down Expand Up @@ -447,7 +456,12 @@ def close(self):
class UrlFetchClient(HTTPClient):
name = "urlfetch"

def __init__(self, verify_ssl_certs=True, proxy=None, deadline=55):
def __init__(
self,
verify_ssl_certs: bool = True,
proxy: Optional[HTTPClient._Proxy] = None,
deadline: int = 55,
):
super(UrlFetchClient, self).__init__(
verify_ssl_certs=verify_ssl_certs, proxy=proxy
)
Expand Down Expand Up @@ -539,7 +553,11 @@ class _ParsedProxy(TypedDict, total=False):
name = "pycurl"
_parsed_proxy: Optional[_ParsedProxy]

def __init__(self, verify_ssl_certs=True, proxy=None):
def __init__(
self,
verify_ssl_certs: bool = True,
proxy: Optional[HTTPClient._Proxy] = None,
):
super(PycurlClient, self).__init__(
verify_ssl_certs=verify_ssl_certs, proxy=proxy
)
Expand Down Expand Up @@ -691,7 +709,11 @@ def close(self):
class Urllib2Client(HTTPClient):
name = "urllib.request"

def __init__(self, verify_ssl_certs=True, proxy=None):
def __init__(
self,
verify_ssl_certs: bool = True,
proxy: Optional[HTTPClient._Proxy] = None,
):
super(Urllib2Client, self).__init__(
verify_ssl_certs=verify_ssl_certs, proxy=proxy
)
Expand All @@ -700,10 +722,10 @@ def __init__(self, verify_ssl_certs=True, proxy=None):
if self._proxy:
# We have to cast _Proxy to Dict[str, str] because pyright is not smart enough to
# realize that all the value types are str.
proxy = urllibrequest.ProxyHandler(
proxy_handler = urllibrequest.ProxyHandler(
cast(Dict[str, str], self._proxy)
)
self._opener = urllibrequest.build_opener(proxy)
self._opener = urllibrequest.build_opener(proxy_handler)

def request(self, method, url, headers, post_data=None):
return self._request_internal(
Expand Down

0 comments on commit 387a5da

Please sign in to comment.