88)
99import sys
1010from typing import (
11+ TYPE_CHECKING ,
1112 Any ,
1213 Final ,
1314 Optional ,
3334 get_default_ipc_path ,
3435)
3536
37+ if sys .platform == "win32" :
38+ if TYPE_CHECKING :
39+ from faster_web3 ._utils .windows import NamedPipe
3640
37- async def async_get_ipc_socket (
38- ipc_path : str , read_buffer_limit : int
39- ) -> Tuple [asyncio .StreamReader , asyncio .StreamWriter ]:
40- if sys .platform == "win32" :
41+ async def async_get_ipc_socket (
42+ ipc_path : str , read_buffer_limit : int
43+ ) -> "NamedPipe" :
4144 # On Windows named pipe is used. Simulate socket with it.
42- from web3 ._utils .windows import (
45+ from faster_web3 ._utils .windows import (
4346 NamedPipe ,
4447 )
4548
4649 return NamedPipe (ipc_path )
47- else :
50+
51+ else :
52+ async def async_get_ipc_socket (
53+ ipc_path : str , read_buffer_limit : int
54+ ) -> Tuple [asyncio .StreamReader , asyncio .StreamWriter ]:
4855 return await asyncio .open_unix_connection (ipc_path , limit = read_buffer_limit )
4956
5057
58+ @final
5159class AsyncIPCProvider (PersistentConnectionProvider ):
52- logger = logging .getLogger ("faster_web3.providers.AsyncIPCProvider" )
60+ logger : Final = logging .getLogger ("faster_web3.providers.AsyncIPCProvider" )
5361
54- _reader : Optional [asyncio .StreamReader ] = None
55- _writer : Optional [asyncio .StreamWriter ] = None
56- _decoder : json .JSONDecoder = json .JSONDecoder ()
62+ _reader : Optional [asyncio .StreamReader ]
63+ _writer : Optional [asyncio .StreamWriter ]
64+ _decoder : Final [ json .JSONDecoder ] = json .JSONDecoder ()
5765
5866 def __init__ (
5967 self ,
@@ -71,7 +79,9 @@ def __init__(
7179 raise Web3TypeError ("ipc_path must be of type string or pathlib.Path" )
7280 self .ipc_path : Final = ipc_path_
7381 super ().__init__ (** kwargs )
74- self .read_buffer_limit = read_buffer_limit
82+ self .read_buffer_limit : Final = read_buffer_limit
83+ self ._reader = None
84+ self ._writer = None
7585
7686 def __str__ (self ) -> str :
7787 return f"<{ self .__class__ .__name__ } { self .ipc_path } >"
0 commit comments