add type alias for httpclient callback

This commit is contained in:
Damien Elmes 2020-01-19 10:06:48 +10:00
parent a47db0d609
commit 67fb3438f3

View File

@ -14,17 +14,17 @@ from requests import Response
HTTP_BUF_SIZE = 64 * 1024 HTTP_BUF_SIZE = 64 * 1024
ProgressCallback = Callable[[int, int], None]
class AnkiRequestsClient: class AnkiRequestsClient:
verify = True verify = True
timeout = 60 timeout = 60
# args are (upload_bytes_in_chunk, download_bytes_in_chunk) # args are (upload_bytes_in_chunk, download_bytes_in_chunk)
progress_hook: Optional[Callable[[int, int], None]] = None progress_hook: Optional[ProgressCallback] = None
def __init__( def __init__(self, progress_hook: Optional[ProgressCallback] = None) -> None:
self, progress_hook: Optional[Callable[[int, int], None]] = None
) -> None:
self.progress_hook = progress_hook self.progress_hook = progress_hook
self.session = requests.Session() self.session = requests.Session()
@ -76,7 +76,7 @@ if os.environ.get("ANKI_NOVERIFYSSL"):
class _MonitoringFile(io.BufferedReader): class _MonitoringFile(io.BufferedReader):
def __init__(self, raw: io.RawIOBase, hook: Optional[Callable[[int, int], None]]): def __init__(self, raw: io.RawIOBase, hook: Optional[ProgressCallback]):
io.BufferedReader.__init__(self, raw) io.BufferedReader.__init__(self, raw)
self.hook = hook self.hook = hook