2020# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121# THE SOFTWARE.
2222
23- import json
23+ import asyncio
2424import base64
2525import functools
26- import asyncio
26+ import json
2727import ssl
28- from typing import Dict , Optional
28+ from typing import Any , Callable , Dict , Optional
2929from urllib import request as http
3030
31-
3231DEFAULT_AUTH_HEADER = "Authorization"
3332ASYNC_FUNCNAME_MARKER = "_async"
3433
@@ -100,21 +99,23 @@ def __init__(
10099 except RuntimeError :
101100 self ._event_loop = asyncio .new_event_loop ()
102101
103- def __getattr__ (self , name : str ):
102+ def __getattr__ (self , name : str ) -> Callable [..., Any ] :
104103 if self .is_async_method_name (name ):
105104
106- async def function (* args , ** kwargs ) :
105+ async def function (* args : Any , ** kwargs : Any ) -> Any :
107106 return await self ._event_loop .run_in_executor (
108107 None ,
109108 functools .partial (
110- self .execute , method = self ._to_camel_case (self .get_funcname_from_async_name (name )), ** kwargs
109+ self .execute ,
110+ method = self ._to_camel_case (self .get_funcname_from_async_name (name )),
111+ ** kwargs ,
111112 ),
112113 )
113114
114115 return function
115116 else :
116117
117- def function (* args , ** kwargs ) :
118+ def function (* args : Any , ** kwargs : Any ) -> Any :
118119 return self .execute (method = self ._to_camel_case (name ), ** kwargs )
119120
120121 return function
@@ -133,7 +134,7 @@ def _to_camel_case(snake_str: str) -> str:
133134 return components [0 ] + "" .join (x .title () for x in components [1 :])
134135
135136 @staticmethod
136- def _parse_response (response : bytes ):
137+ def _parse_response (response : bytes ) -> Any :
137138 if not response :
138139 raise ClientError ("Empty response from server" )
139140 try :
@@ -147,7 +148,7 @@ def _parse_response(response: bytes):
147148 except ValueError as e :
148149 raise ClientError (f"Failed to parse JSON response: { e } " )
149150
150- def _do_request (self , headers : Dict [str , str ], body : Dict ) :
151+ def _do_request (self , headers : Dict [str , str ], body : Dict [ str , Any ]) -> Any :
151152 try :
152153 request = http .Request (self ._url , headers = headers , data = json .dumps (body ).encode ())
153154
@@ -164,7 +165,7 @@ def _do_request(self, headers: Dict[str, str], body: Dict):
164165 raise ClientError (str (e ))
165166 return self ._parse_response (response )
166167
167- def execute (self , method : str , ** kwargs ) :
168+ def execute (self , method : str , ** kwargs : Any ) -> Any :
168169 """
169170 Call a remote Kanboard API procedure.
170171
0 commit comments