Skip to content

Commit

Permalink
Add type annotations to download.py and fetcher.py
Browse files Browse the repository at this point in the history
Add the stub for the requests package (types-requests)
to requirements-tests.txt.

Add urllib3 to the ignored imports. The project seems
to have added type annotations already but has not
released a version including them yet.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
  • Loading branch information
sechkova committed Aug 11, 2021
1 parent caa95c9 commit d306370
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ isort
pylint
mypy
bandit
types-requests
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ files =

[mypy-securesystemslib.*]
ignore_missing_imports = True

[mypy-urllib3.*]
ignore_missing_imports = True
8 changes: 4 additions & 4 deletions tuf/ngclient/_internal/requests_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import logging
import time
from typing import Iterator, Optional
from typing import Dict, Iterator, Optional
from urllib import parse

# Imports
Expand All @@ -31,7 +31,7 @@ class RequestsFetcher(FetcherInterface):
session per scheme+hostname combination.
"""

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

# Default settings
self.socket_timeout: int = 4 # seconds
Expand Down Expand Up @@ -146,7 +146,7 @@ def _chunks(
finally:
response.close()

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

0 comments on commit d306370

Please sign in to comment.