Skip to content

Commit bbf4fd7

Browse files
committed
feat: compile future helpers
1 parent 30abd71 commit bbf4fd7

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

dank_mids/helpers/future.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import asyncio
2+
import weakref
13
from asyncio import (
24
AbstractEventLoop,
35
Future,
@@ -8,42 +10,50 @@
810
sleep,
911
)
1012
from time import time
11-
from typing import TYPE_CHECKING, Any, Generator, Optional, Union
13+
from typing import TYPE_CHECKING, Any, Final, Generator, Optional, Union, final
1214
from weakref import ProxyType, proxy
1315

1416
from web3.types import RPCResponse
1517

1618
from dank_mids._logging import DEBUG, getLogger
1719
from dank_mids.helpers._errors import error_logger_debug
20+
from dank_mids.types import T
1821

1922
if TYPE_CHECKING:
2023
from dank_mids._requests import _RequestBase, _Response
2124

2225

23-
logger = getLogger("dank_mids.future")
26+
logger: Final = getLogger("dank_mids.future")
2427

25-
_logger_is_enabled_for = logger.isEnabledFor
26-
_logger_log = logger._log
28+
_logger_is_enabled_for: Final = logger.isEnabledFor
29+
_logger_log: Final = logger._log
2730

28-
_future_init = Future.__init__
29-
_future_await = Future.__await__
30-
_future_set_result = Future.set_result
31-
_future_set_exc = Future.set_exception
31+
_future_init: Final = Future.__init__
32+
_future_await: Final = Future.__await__
33+
_future_set_result: Final = Future.set_result
34+
_future_set_exc: Final = Future.set_exception
3235

36+
create_task: Final = asyncio.create_task
37+
get_running_loop: Final = asyncio.get_running_loop
38+
sleep: Final = asyncio.sleep
3339

34-
class DebuggableFuture(Future):
40+
proxy: Final = weakref.proxy
41+
42+
43+
@final
44+
class DebuggableFuture(Future[T]):
3545
# default values
3646
_debug_logs_enabled: bool = False
3747
__debug_daemon_task: Optional["Task[None]"] = None
3848

3949
# type hints
4050
_result: Optional[RPCResponse]
4151

42-
def __init__(self, owner: "_RequestBase", loop: AbstractEventLoop) -> None:
52+
def __init__(self, owner: "_RequestBase", loop: AbstractEventLoop) -> None: # type: ignore [type-arg]
4353
_future_init(self, loop=loop)
4454
if _logger_is_enabled_for(DEBUG):
4555
self._debug_logs_enabled = True
46-
self._owner: ProxyType["_RequestBase[_Response]"] = proxy(owner)
56+
self._owner: weakref.ProxyType["_RequestBase[_Response]"] = proxy(owner) # type: ignore [valid-type]
4757

4858
def __await__(self) -> Generator[Any, None, RPCResponse]:
4959
if self._debug_logs_enabled and self.__debug_daemon_task is None:

0 commit comments

Comments
 (0)