3333
3434import json
3535from os .path import isfile as os_path_isfile
36- from typing import IO , Optional
36+ from typing import BinaryIO , Dict , Optional
3737from requests .models import Response
3838
3939from flatten_dict import flatten
@@ -142,7 +142,7 @@ def __getattr__(self, value: str):
142142 return c
143143
144144 @property
145- def headers (self ) -> dict :
145+ def headers (self ) -> Dict :
146146 """dict: Headers REST headers from response"""
147147 return self ._headers
148148
@@ -157,11 +157,11 @@ def verify(self) -> bool:
157157 return self ._verify
158158
159159 @property
160- def cert (self ) -> str :
160+ def cert (self ) -> Optional [ str ] :
161161 """str: filepath containing authorisation certificate."""
162162 return self ._cert
163163
164- def __add_headers (self , headers ) :
164+ def __add_headers (self , headers : Optional [ Dict ]) -> Dict :
165165 """docstring"""
166166 if headers is not None :
167167 newheaders = {** self .headers , ** headers }
@@ -171,8 +171,8 @@ def __add_headers(self, headers):
171171 return newheaders
172172
173173 def get (
174- self , subpath : str , identity : str , * , headers : Optional [dict ] = None
175- ) -> dict :
174+ self , subpath : str , identity : str , * , headers : Optional [Dict ] = None
175+ ) -> Dict :
176176 """GET method (REST)
177177
178178 Args:
@@ -198,7 +198,12 @@ def get(
198198 return response .json ()
199199
200200 def get_file (
201- self , subpath : str , identity : str , fd : IO , * , headers : Optional [dict ] = None
201+ self ,
202+ subpath : str ,
203+ identity : str ,
204+ fd : BinaryIO ,
205+ * ,
206+ headers : Optional [Dict ] = None ,
202207 ) -> Response :
203208 """GET method (REST) - chunked
204209
@@ -232,7 +237,7 @@ def get_file(
232237
233238 return response
234239
235- def post (self , path : str , request : dict , * , headers : Optional [dict ] = None ) -> dict :
240+ def post (self , path : str , request : Dict , * , headers : Optional [Dict ] = None ) -> Dict :
236241 """POST method (REST)
237242
238243 Creates an entity
@@ -261,7 +266,7 @@ def post(self, path: str, request: dict, *, headers: Optional[dict] = None) -> d
261266
262267 return response .json ()
263268
264- def post_file (self , path : str , fd : IO , mtype : str ) -> dict :
269+ def post_file (self , path : str , fd : BinaryIO , mtype : str ) -> Dict :
265270 """POST method (REST) - upload binary
266271
267272 Uploads a file to an endpoint
@@ -286,7 +291,7 @@ def post_file(self, path: str, fd: IO, mtype: str) -> dict:
286291 }
287292 response = requests .post (
288293 SEP .join ((self .url , ROOT , path )),
289- data = multipart ,
294+ data = multipart , # type: ignore https://github.com/requests/toolbelt/issues/312
290295 headers = self .__add_headers (headers ),
291296 verify = self .verify ,
292297 cert = self .cert ,
@@ -299,8 +304,8 @@ def post_file(self, path: str, fd: IO, mtype: str) -> dict:
299304 return response .json ()
300305
301306 def delete (
302- self , subpath : str , identity : str , * , headers : Optional [dict ] = None
303- ) -> dict :
307+ self , subpath : str , identity : str , * , headers : Optional [Dict ] = None
308+ ) -> Dict :
304309 """DELETE method (REST)
305310
306311 Deletes an entity
@@ -331,10 +336,10 @@ def patch(
331336 self ,
332337 subpath : str ,
333338 identity : str ,
334- request : dict ,
339+ request : Dict ,
335340 * ,
336- headers : Optional [dict ] = None ,
337- ) -> dict :
341+ headers : Optional [Dict ] = None ,
342+ ) -> Dict :
338343 """PATCH method (REST)
339344
340345 Updates the specified entity.
@@ -364,7 +369,7 @@ def patch(
364369
365370 return response .json ()
366371
367- def __list (self , path , args , * , headers = None ):
372+ def __list (self , path , args , * , headers = None ) -> Response :
368373 if args :
369374 path = "?" .join ((path , args ))
370375
@@ -381,14 +386,14 @@ def __list(self, path, args, *, headers=None):
381386 return response
382387
383388 @staticmethod
384- def __query (query ):
389+ def __query (query : Optional [ Dict ] ):
385390 return query and "&" .join (
386391 sorted (f"{ k } ={ v } " for k , v in flatten (query , reducer = "dot" ).items ())
387392 )
388393
389394 def get_by_signature (
390- self , path : str , field : str , query : dict , * , headers : Optional [dict ] = None
391- ) -> dict :
395+ self , path : str , field : str , query : Dict , * , headers : Optional [Dict ] = None
396+ ) -> Dict :
392397 """GET method (REST) with query string
393398
394399 Reads an entity indirectly by searching for its signature
@@ -417,7 +422,7 @@ def get_by_signature(
417422
418423 response = self .__list (
419424 path ,
420- "&" .join ((a for a in (paging , qry ) if a )),
425+ "&" .join ((a for a in (paging , qry ) if a )), # type: ignore
421426 headers = headers ,
422427 )
423428
@@ -436,7 +441,7 @@ def get_by_signature(
436441
437442 return records [0 ]
438443
439- def count (self , path : str , * , query : Optional [dict ] = None ) -> int :
444+ def count (self , path : str , * , query : Optional [Dict ] = None ) -> int :
440445 """GET method (REST) with query string
441446
442447 Returns the count of objects that match query
@@ -456,7 +461,7 @@ def count(self, path: str, *, query: Optional[dict] = None) -> int:
456461
457462 response = self .__list (
458463 path ,
459- "&" .join ((a for a in (paging , qry ) if a )),
464+ "&" .join ((a for a in (paging , qry ) if a )), # type: ignore
460465 headers = headers ,
461466 )
462467
@@ -467,9 +472,9 @@ def list(
467472 path : str ,
468473 field : str ,
469474 * ,
470- page_size : Optional [ int ] = None ,
471- query : Optional [dict ] = None ,
472- headers : Optional [dict ] = None ,
475+ page_size : int = None ,
476+ query : Optional [Dict ] = None ,
477+ headers : Optional [Dict ] = None ,
473478 ):
474479 """GET method (REST) with query string
475480
@@ -502,7 +507,7 @@ def list(
502507 while True :
503508 response = self .__list (
504509 path ,
505- "&" .join ((a for a in (paging , qry ) if a )),
510+ "&" .join ((a for a in (paging , qry ) if a )), # type: ignore
506511 headers = headers ,
507512 )
508513 data = response .json ()
0 commit comments