66import inspect
77import random
88import time
9- from types import FrameType
109from typing import TYPE_CHECKING , Any , ClassVar , cast
1110from urllib .parse import parse_qs , urlparse
1211
2019
2120if TYPE_CHECKING :
2221 from collections .abc import Iterable
22+ from types import FrameType
2323
2424 import requests
2525 from backoff .types import Details
26+ from singer_sdk .helpers .types import Context
2627
2728EMPTY_REPO_ERROR_STATUS = 409
2829
@@ -61,7 +62,7 @@ def url_base(self) -> str:
6162 def http_headers (self ) -> dict [str , str ]:
6263 """Return the http headers needed."""
6364 headers = {"Accept" : "application/vnd.github.v3+json" }
64- headers ["User-Agent" ] = cast (str , self .config .get ("user_agent" , "tap-github" ))
65+ headers ["User-Agent" ] = cast (" str" , self .config .get ("user_agent" , "tap-github" ))
6566 return headers
6667
6768 def get_next_page_token (
@@ -74,7 +75,8 @@ def get_next_page_token(
7475 previous_token
7576 and self .MAX_RESULTS_LIMIT
7677 and (
77- cast (int , previous_token ) * self .MAX_PER_PAGE >= self .MAX_RESULTS_LIMIT
78+ cast ("int" , previous_token ) * self .MAX_PER_PAGE
79+ >= self .MAX_RESULTS_LIMIT
7880 )
7981 ):
8082 return None
@@ -139,7 +141,7 @@ def get_next_page_token(
139141
140142 def get_url_params (
141143 self ,
142- context : dict | None ,
144+ context : Context | None ,
143145 next_page_token : Any | None , # noqa: ANN401
144146 ) -> dict [str , Any ]:
145147 """Return a dictionary of values to be used in URL parameterization."""
@@ -172,7 +174,7 @@ def get_url_params(
172174 params [since_key ] = since .isoformat (sep = "T" )
173175 # Leverage conditional requests to save API quotas
174176 # https://github.community/t/how-does-if-modified-since-work/139627
175- self ._http_headers ["If-modified-since" ] = email .utils .format_datetime (since )
177+ self .http_headers ["If-modified-since" ] = email .utils .format_datetime (since )
176178 return params
177179
178180 def validate_response (self , response : requests .Response ) -> None :
@@ -270,7 +272,7 @@ def parse_response(self, response: requests.Response) -> Iterable[dict]:
270272
271273 yield from results
272274
273- def post_process (self , row : dict , context : dict [ str , str ] | None = None ) -> dict :
275+ def post_process (self , row : dict , context : Context | None = None ) -> dict :
274276 """Add `repo_id` by default to all streams."""
275277 if context is not None and "repo_id" in context :
276278 row ["repo_id" ] = context ["repo_id" ]
@@ -283,8 +285,8 @@ def backoff_handler(self, details: Details) -> None:
283285 # FIXME: replace this once https://github.com/litl/backoff/issues/158
284286 # is fixed
285287 exc = cast (
286- FrameType ,
287- cast (FrameType , cast (FrameType , inspect .currentframe ()).f_back ).f_back ,
288+ " FrameType" ,
289+ cast (" FrameType" , cast (" FrameType" , inspect .currentframe ()).f_back ).f_back ,
288290 ).f_locals ["e" ]
289291 if (
290292 exc .response is not None
@@ -300,7 +302,7 @@ def calculate_sync_cost(
300302 self ,
301303 request : requests .PreparedRequest ,
302304 response : requests .Response ,
303- context : dict | None ,
305+ context : Context | None ,
304306 ) -> dict [str , int ]:
305307 """Return the cost of the last REST API call."""
306308 return {"rest" : 1 , "graphql" : 0 , "search" : 0 }
@@ -448,11 +450,11 @@ def get_next_page_token(
448450
449451 def get_url_params (
450452 self ,
451- context : dict | None ,
453+ context : Context | None ,
452454 next_page_token : Any | None , # noqa: ANN401
453455 ) -> dict [str , Any ]:
454456 """Return a dictionary of values to be used in URL parameterization."""
455- params = context . copy ( ) if context else {}
457+ params = dict ( context ) if context else {}
456458 params ["per_page" ] = self .MAX_PER_PAGE
457459 if next_page_token :
458460 params .update (next_page_token )
@@ -467,7 +469,7 @@ def calculate_sync_cost(
467469 self ,
468470 request : requests .PreparedRequest ,
469471 response : requests .Response ,
470- context : dict | None ,
472+ context : Context | None ,
471473 ) -> dict [str , int ]:
472474 """Return the cost of the last graphql API call."""
473475 costgen = extract_jsonpath ("$.data.rateLimit.cost" , input = response .json ())
0 commit comments