Skip to content

Commit

Permalink
fix: aiohttp DeprecationWarning (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Jul 27, 2024
1 parent 7a32e8e commit 9ce0c56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions dank_mids/helpers/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from typing import Any, Callable, List, Optional, overload

import msgspec
from aiohttp import ClientSession as DefaultClientSession
from aiohttp import ClientTimeout, TCPConnector
from aiohttp import ClientSession, ClientTimeout, TCPConnector
from aiohttp.client_exceptions import ClientResponseError
from aiohttp.typedefs import DEFAULT_JSON_DECODER, JSONDecoder
from aiolimiter import AsyncLimiter
Expand Down Expand Up @@ -83,10 +82,10 @@ async def post(endpoint: str, *args, loads: JSONDecoder = DEFAULT_JSON_DECODER,
session = await get_session()
return await session.post(endpoint, *args, loads=loads, **kwargs)

async def get_session() -> "ClientSession":
async def get_session() -> "DankClientSession":
return await _get_session_for_thread(get_ident())

class ClientSession(DefaultClientSession):
class DankClientSession(ClientSession):
async def post(self, endpoint: str, *args, loads: JSONDecoder = DEFAULT_JSON_DECODER, _retry_after: float = 1, **kwargs) -> bytes: # type: ignore [override]
# Process input arguments.
if isinstance(kwargs.get('data'), PartialRequest):
Expand Down Expand Up @@ -129,17 +128,17 @@ async def post(self, endpoint: str, *args, loads: JSONDecoder = DEFAULT_JSON_DEC
tried += 1

@alru_cache(maxsize=None)
async def _get_session_for_thread(thread_ident: int) -> ClientSession:
async def _get_session_for_thread(thread_ident: int) -> DankClientSession:
"""
This makes our ClientSession threadsafe just in case.
Most everything should be run in main thread though.
"""
return ClientSession(
return DankClientSession(
connector = TCPConnector(limit=32),
headers = {'content-type': 'application/json'},
timeout = ClientTimeout(ENVIRONMENT_VARIABLES.AIOHTTP_TIMEOUT), # type: ignore [arg-type, attr-defined]
raise_for_status = True,
read_bufsize=2**20, # 1mb
)

_limited: List[ClientSession] = []
_limited: List[DankClientSession] = []
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dank-mids"
version = "4.20.94"
version = "4.20.95"
description = "Multicall batching middleware for asynchronous scripts using web3.py"
authors = ["BobTheBuidler <[email protected]>"]
homepage = "https://github.com/BobTheBuidler/dank_mids"
Expand Down

0 comments on commit 9ce0c56

Please sign in to comment.