Skip to content

Commit a89bec5

Browse files
committed
Add type annotations to download.py and fetcher.py
Run mypy with --install-types and --non-interactive options to install all suggested stub packages. In our case this is the stub for the requests package. Include urllib3 to the ignored imports. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
1 parent 88795a1 commit a89bec5

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ files =
2222

2323
[mypy-securesystemslib.*]
2424
ignore_missing_imports = True
25+
26+
[mypy-urllib3.*]
27+
ignore_missing_imports = True

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ commands =
5151
# work, unfortunately each subdirectory has to be ignored explicitly.
5252
pylint -j 0 tuf --ignore=tuf/api,tuf/api/serialization,tuf/ngclient,tuf/ngclient/_internal
5353

54-
mypy
54+
mypy --install-types --non-interactive
5555

5656
bandit -r tuf

tuf/ngclient/_internal/requests_fetcher.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import logging
99
import time
10-
from typing import Iterator, Optional
10+
from typing import Dict, Iterator, Optional
1111
from urllib import parse
1212

1313
# Imports
@@ -31,7 +31,7 @@ class RequestsFetcher(FetcherInterface):
3131
session per scheme+hostname combination.
3232
"""
3333

34-
def __init__(self):
34+
def __init__(self) -> None:
3535
# http://docs.python-requests.org/en/master/user/advanced/#session-objects:
3636
#
3737
# "The Session object allows you to persist certain parameters across
@@ -46,7 +46,7 @@ def __init__(self):
4646
# improve efficiency, but avoiding sharing state between different
4747
# hosts-scheme combinations to minimize subtle security issues.
4848
# Some cookies may not be HTTP-safe.
49-
self._sessions = {}
49+
self._sessions: Dict[str, requests.Session] = {}
5050

5151
# Default settings
5252
self.socket_timeout: int = 4 # seconds
@@ -146,7 +146,7 @@ def _chunks(
146146
finally:
147147
response.close()
148148

149-
def _get_session(self, url):
149+
def _get_session(self, url: str) -> requests.Session:
150150
"""Returns a different customized requests.Session per schema+hostname
151151
combination.
152152
"""

0 commit comments

Comments
 (0)