11"""API functions for interacting with Pica AuthKit."""
22
33import asyncio
4- from typing import Dict , List , Optional
4+ from typing import Optional , cast
55
66import httpx
77
1010
1111async def _paginate_authkit_connections_async (
1212 url : str ,
13- headers : Dict [str , str ],
13+ headers : dict [str , str ],
1414 payload : Optional [CreateEventLinkPayload ] = None ,
1515 options : Optional [ConnectorPaginationOptions ] = None ,
1616) -> AuthkitResponse :
@@ -44,7 +44,7 @@ async def fetch_authkit_page(
4444 headers = headers ,
4545 )
4646 response .raise_for_status ()
47- return response .json ()
47+ return cast ( AuthkitResponse , response .json () )
4848
4949 async def fetch_page_with_retry (client : httpx .AsyncClient , page : int ) -> AuthkitResponse :
5050 """Fetch a page with retry logic."""
@@ -77,7 +77,7 @@ async def fetch_page_with_retry(client: httpx.AsyncClient, page: int) -> Authkit
7777 remaining_pages = list (range (2 , pages + 1 ))
7878
7979 # Execute requests in batches to avoid overwhelming the API
80- responses : List [AuthkitResponse ] = [first_response ]
80+ responses : list [AuthkitResponse ] = [first_response ]
8181
8282 for i in range (0 , len (remaining_pages ), max_concurrent_requests ):
8383 batch = remaining_pages [i : i + max_concurrent_requests ]
@@ -109,7 +109,7 @@ async def fetch_page_with_retry(client: httpx.AsyncClient, page: int) -> Authkit
109109
110110def _paginate_authkit_connections_sync (
111111 url : str ,
112- headers : Dict [str , str ],
112+ headers : dict [str , str ],
113113 payload : Optional [CreateEventLinkPayload ] = None ,
114114 options : Optional [ConnectorPaginationOptions ] = None ,
115115) -> AuthkitResponse :
@@ -140,7 +140,7 @@ def fetch_authkit_page(client: httpx.Client, page: int, page_limit: int) -> Auth
140140 headers = headers ,
141141 )
142142 response .raise_for_status ()
143- return response .json ()
143+ return cast ( AuthkitResponse , response .json () )
144144
145145 def fetch_page_with_retry (client : httpx .Client , page : int ) -> AuthkitResponse :
146146 """Fetch a page with retry logic."""
@@ -175,7 +175,7 @@ def fetch_page_with_retry(client: httpx.Client, page: int) -> AuthkitResponse:
175175 remaining_pages = list (range (2 , pages + 1 ))
176176
177177 # Fetch remaining pages sequentially (no concurrent requests in sync mode)
178- responses : List [AuthkitResponse ] = [first_response ]
178+ responses : list [AuthkitResponse ] = [first_response ]
179179
180180 for page in remaining_pages :
181181 try :
@@ -203,7 +203,7 @@ def fetch_page_with_retry(client: httpx.Client, page: int) -> AuthkitResponse:
203203
204204
205205async def create_event_link_token_async (
206- headers : Dict [str , str ],
206+ headers : dict [str , str ],
207207 url : str ,
208208 payload : Optional [CreateEventLinkPayload ] = None ,
209209) -> Optional [AuthkitResponse ]:
@@ -226,13 +226,13 @@ async def create_event_link_token_async(
226226 return authkit_response
227227 except httpx .HTTPStatusError as error :
228228 # Return error response data if available
229- return error .response .json () if error .response else None
229+ return cast ( AuthkitResponse , error .response .json () ) if error .response else None
230230 except Exception :
231231 return None
232232
233233
234234def create_event_link_token_sync (
235- headers : Dict [str , str ],
235+ headers : dict [str , str ],
236236 url : str ,
237237 payload : Optional [CreateEventLinkPayload ] = None ,
238238) -> Optional [AuthkitResponse ]:
@@ -255,7 +255,7 @@ def create_event_link_token_sync(
255255 return authkit_response
256256 except httpx .HTTPStatusError as error :
257257 # Return error response data if available
258- return error .response .json () if error .response else None
258+ return cast ( AuthkitResponse , error .response .json () ) if error .response else None
259259 except Exception :
260260 return None
261261
0 commit comments