55 Coroutine ,
66 Dict ,
77 Optional ,
8- Sequence ,
98 Tuple ,
109 TypeVar ,
1110 Union ,
12- cast ,
11+ overload ,
1312)
1413
1514from eth_abi .codec import (
2726)
2827from web3 .method import (
2928 Method ,
29+ RequestArgs ,
30+ ResponseFormatters ,
3031)
3132from web3 .providers .persistent import (
3233 PersistentConnectionProvider ,
3334)
3435from web3 .types import (
3536 FormattedEthSubscriptionResponse ,
36- RPCEndpoint ,
3737 RPCResponse ,
38+ TFunc ,
3839)
3940
4041if TYPE_CHECKING :
@@ -58,34 +59,52 @@ def apply_result_formatters(
5859TReturn = TypeVar ("TReturn" )
5960
6061
62+ @overload
63+ def retrieve_request_information_for_batching (
64+ w3 : "AsyncWeb3" ,
65+ module : "Module" ,
66+ method : Method [Callable [..., Any ]],
67+ ) -> Callable [..., Coroutine [Any , Any , Tuple [RequestArgs , ResponseFormatters [Any ]]]]:
68+ ...
69+
70+
71+ @overload
72+ def retrieve_request_information_for_batching (
73+ w3 : "Web3" ,
74+ module : "Module" ,
75+ method : Method [Callable [..., Any ]],
76+ ) -> Callable [..., Tuple [RequestArgs , ResponseFormatters [Any ]]]:
77+ ...
78+
79+
6180@curry
6281def retrieve_request_information_for_batching (
6382 w3 : Union ["AsyncWeb3" , "Web3" ],
6483 module : "Module" ,
6584 method : Method [Callable [..., Any ]],
6685) -> Union [
67- Callable [..., Tuple [Tuple [ RPCEndpoint , Any ], Sequence [Any ]]],
68- Callable [..., Coroutine [Any , Any , Tuple [Tuple [ RPCEndpoint , Any ], Sequence [Any ]]]],
86+ Callable [..., Tuple [RequestArgs , ResponseFormatters [Any ]]],
87+ Callable [..., Coroutine [Any , Any , Tuple [RequestArgs , ResponseFormatters [Any ]]]],
6988]:
7089 async def async_inner (
7190 * args : Any , ** kwargs : Any
72- ) -> Tuple [Tuple [RPCEndpoint , Any ], Sequence [Any ]]:
91+ ) -> Tuple [RequestArgs , ResponseFormatters [Any ]]:
92+ response_formatters : ResponseFormatters [Any ]
7393 (method_str , params ), response_formatters = method .process_params (
7494 module , * args , ** kwargs
7595 )
7696 if isinstance (w3 .provider , PersistentConnectionProvider ):
7797 w3 .provider ._request_processor .cache_request_information (
78- None , cast ( RPCEndpoint , method_str ) , params , response_formatters
98+ None , method_str , params , response_formatters
7999 )
80- return (cast ( RPCEndpoint , method_str ) , params ), response_formatters
100+ return (method_str , params ), response_formatters
81101
82- def inner (
83- * args : Any , ** kwargs : Any
84- ) -> Tuple [Tuple [RPCEndpoint , Any ], Sequence [Any ]]:
102+ def inner (* args : Any , ** kwargs : Any ) -> Tuple [RequestArgs , ResponseFormatters [Any ]]:
103+ response_formatters : ResponseFormatters [Any ]
85104 (method_str , params ), response_formatters = method .process_params (
86105 module , * args , ** kwargs
87106 )
88- return (cast ( RPCEndpoint , method_str ) , params ), response_formatters
107+ return (method_str , params ), response_formatters
89108
90109 return async_inner if module .is_async else inner
91110
@@ -97,6 +116,8 @@ def retrieve_blocking_method_call_fn(
97116 method : Method [Callable [..., TReturn ]],
98117) -> Callable [..., Union [TReturn , LogFilter ]]:
99118 def caller (* args : Any , ** kwargs : Any ) -> Union [TReturn , LogFilter ]:
119+ response_formatters : ResponseFormatters [Any ]
120+
100121 try :
101122 (method_str , params ), response_formatters = method .process_params (
102123 module , * args , ** kwargs
@@ -133,6 +154,8 @@ def retrieve_async_method_call_fn(
133154 async def caller (
134155 * args : Any , ** kwargs : Any
135156 ) -> Union [RPCResponse , FormattedEthSubscriptionResponse , AsyncLogFilter ]:
157+ response_formatters : ResponseFormatters [Any ]
158+
136159 try :
137160 (method_str , params ), response_formatters = method .process_params (
138161 module , * args , ** kwargs
@@ -142,7 +165,7 @@ async def caller(
142165
143166 if isinstance (async_w3 .provider , PersistentConnectionProvider ):
144167 return await async_w3 .manager .socket_request (
145- cast ( RPCEndpoint , method_str ) ,
168+ method_str ,
146169 params ,
147170 response_formatters = response_formatters ,
148171 )
@@ -167,12 +190,22 @@ async def caller(
167190class Module :
168191 is_async = False
169192
193+ retrieve_request_information : Callable [
194+ [Method [TFunc ]],
195+ Union [
196+ Callable [..., Tuple [RequestArgs , ResponseFormatters [Any ]]],
197+ Callable [
198+ ..., Coroutine [Any , Any , Tuple [RequestArgs , ResponseFormatters [Any ]]]
199+ ],
200+ ],
201+ ]
202+
170203 def __init__ (self , w3 : Union ["AsyncWeb3" , "Web3" ]) -> None :
171204 if self .is_async :
172205 self .retrieve_caller_fn = retrieve_async_method_call_fn (w3 , self )
173206 else :
174207 self .retrieve_caller_fn = retrieve_blocking_method_call_fn (w3 , self )
175- self .retrieve_request_information = retrieve_request_information_for_batching (
208+ self .retrieve_request_information = retrieve_request_information_for_batching ( # type: ignore [call-overload]
176209 w3 , self
177210 )
178211 self .w3 = w3
0 commit comments