Skip to content
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

Add more types to _http_client.py #1169

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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