Skip to content

Commit b92435e

Browse files
committed
Fix type signatures
This was missed in an earlier commit. mypy is enabled in the gate to ensure we spot this sooner next time. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 9c6b019 commit b92435e

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

git_pw/api.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
if 0: # noqa
1616
from typing import Dict # noqa
17+
from typing import List # noqa
18+
from typing import Tuple # noqa
19+
20+
Filters = List[Tuple[str, str]]
1721

1822
CONF = config.CONF
1923
LOG = logging.getLogger(__name__)
@@ -91,13 +95,17 @@ def _handle_error(operation, exc):
9195

9296

9397
def get(url, params=None, stream=False):
94-
# type: (str, dict, bool) -> requests.Response
98+
# type: (str, Filters, bool) -> requests.Response
9599
"""Make GET request and handle errors."""
96100
LOG.debug('GET %s', url)
97101

98102
try:
99-
rsp = requests.get(url, auth=_get_auth(), headers=_get_headers(),
100-
params=params, stream=stream)
103+
# TODO(stephenfin): We only use a subset of the types possible for
104+
# 'params' (namely a list of tuples) but it doesn't seem possible to
105+
# indicate this
106+
rsp = requests.get( # type: ignore
107+
url, auth=_get_auth(), headers=_get_headers(), params=params,
108+
stream=stream)
101109
rsp.raise_for_status()
102110
except requests.exceptions.RequestException as exc:
103111
_handle_error('fetch', exc)
@@ -107,7 +115,8 @@ def get(url, params=None, stream=False):
107115
return rsp
108116

109117

110-
def put(url, data): # type: (str, dict) -> requests.Response
118+
def put(url, data):
119+
# type: (str, dict) -> requests.Response
111120
"""Make PUT request and handle errors."""
112121
LOG.debug('PUT %s, data=%r', url, data)
113122

@@ -123,15 +132,15 @@ def put(url, data): # type: (str, dict) -> requests.Response
123132
return rsp
124133

125134

126-
def download(url, params=None): # type: (str, dict) -> None
135+
def download(url, params=None):
136+
# type: (str, Filters) -> str
127137
"""Retrieve a specific API resource and save it to a file.
128138
129139
GET /{resource}/{resourceID}/
130140
131141
Arguments:
132-
resource_type (str): The resource endpoint name.
133-
resource_id (int/str): The ID for the specific resource.
134-
params (dict/list): Additional parameters.
142+
url: The resource URL.
143+
params: Additional parameters.
135144
136145
Returns:
137146
A path to an output file containing the content.
@@ -148,7 +157,8 @@ def download(url, params=None): # type: (str, dict) -> None
148157
return output_path
149158

150159

151-
def index(resource_type, params=None): # type: (str, dict) -> dict
160+
def index(resource_type, params=None):
161+
# type: (str, Filters) -> dict
152162
"""List API resources.
153163
154164
GET /{resource}/
@@ -157,8 +167,8 @@ def index(resource_type, params=None): # type: (str, dict) -> dict
157167
fashion.
158168
159169
Arguments:
160-
resource_type (str): The resource endpoint name.
161-
params (dict/list): Additional parameters, filters.
170+
resource_type: The resource endpoint name.
171+
params: Additional parameters, filters.
162172
163173
Returns:
164174
A list of dictionaries, representing the summary view of each resource.
@@ -175,15 +185,15 @@ def index(resource_type, params=None): # type: (str, dict) -> dict
175185

176186

177187
def detail(resource_type, resource_id, params=None):
178-
# type: (str, int, dict) -> dict
188+
# type: (str, int, Filters) -> Dict
179189
"""Retrieve a specific API resource.
180190
181191
GET /{resource}/{resourceID}/
182192
183193
Arguments:
184-
resource_type (str): The resource endpoint name.
185-
resource_id (int/str): The ID for the specific resource.
186-
params (dict/list): Additional parameters.
194+
resource_type: The resource endpoint name.
195+
resource_id: The ID for the specific resource.
196+
params: Additional parameters.
187197
188198
Returns:
189199
A dictionary representing the detailed view of a given resource.
@@ -202,9 +212,9 @@ def update(resource_type, resource_id, data):
202212
PUT /{resource}/{resourceID}/
203213
204214
Arguments:
205-
resource_type (str): The resource endpoint name.
206-
resource_id (int/str): The ID for the specific resource.
207-
params (dict/list): Fields to update.
215+
resource_type: The resource endpoint name.
216+
resource_id: The ID for the specific resource.
217+
params: Fields to update.
208218
209219
Returns:
210220
A dictionary representing the detailed view of a given resource.

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
minversion = 2.0
3-
envlist = pep8,docs
3+
envlist = pep8,mypy,docs
44

55
[testenv]
66
deps =

0 commit comments

Comments
 (0)