Skip to content

Commit

Permalink
Merge pull request #69 from norinorin/fix/mypy
Browse files Browse the repository at this point in the history
Fix some type issues
  • Loading branch information
Esmeray6 authored Nov 27, 2021
2 parents cac1004 + af385f9 commit bc3c062
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion topgg/autopost.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _refresh_state(self) -> None:
self._task = None
self._stopping = False

def _fut_done_callback(self, future: "asyncio.Future" = None):
def _fut_done_callback(self, future: "asyncio.Future") -> None:
self._refresh_state()
if future.cancelled():
return
Expand Down
12 changes: 8 additions & 4 deletions topgg/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ class HTTPClient:
"""

def __init__(
self, token: str, *, session: aiohttp.ClientSession = None, **kwargs: Any
self,
token: str,
*,
session: Optional[aiohttp.ClientSession] = None,
**kwargs: Any,
) -> None:
self.BASE = "https://top.gg/api"
self.token = token
self._own_session = session is None
self.session = session or aiohttp.ClientSession(**kwargs)
self.session: aiohttp.ClientSession = session or aiohttp.ClientSession(**kwargs)
self.global_rate_limiter = AsyncRateLimiter(
max_calls=99, period=1, callback=_rate_limit_handler
)
Expand Down Expand Up @@ -110,7 +114,7 @@ async def request(self, method: str, endpoint: str, **kwargs: Any) -> dict:
kwargs["headers"] = headers

for _ in range(2):
async with rate_limiters:
async with rate_limiters: # type: ignore
async with self.session.request(method, url, **kwargs) as resp:
_LOGGER.debug(
"%s %s with %s has returned %s",
Expand All @@ -129,7 +133,7 @@ async def request(self, method: str, endpoint: str, **kwargs: Any) -> dict:
fmt = "We are being ratelimited. Retrying in %.2f seconds (%.3f minutes)."

# sleep a bit
retry_after = float(resp.headers.get("Retry-After"))
retry_after = float(resp.headers["Retry-After"])
mins = retry_after / 60
_LOGGER.warning(fmt, retry_after, mins)

Expand Down

0 comments on commit bc3c062

Please sign in to comment.