Skip to content

Commit 89694a2

Browse files
committed
chore: make formatter typing more specific
1 parent 7bec6f7 commit 89694a2

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

web3/middleware/validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
FormattingMiddlewareBuilder,
3737
)
3838
from web3.types import (
39-
Formatters,
4039
FormattersDict,
40+
RequestFormatters,
4141
RPCEndpoint,
4242
TxParams,
4343
)
@@ -151,7 +151,7 @@ def build_method_validators(w3: "Web3", method: RPCEndpoint) -> FormattersDict:
151151
async def async_build_method_validators(
152152
async_w3: "AsyncWeb3", method: RPCEndpoint
153153
) -> FormattersDict:
154-
request_formatters: Formatters = {}
154+
request_formatters: RequestFormatters = {}
155155
if RPCEndpoint(method) in METHODS_TO_VALIDATE:
156156
w3_chain_id = await async_w3.eth.chain_id
157157
for method in METHODS_TO_VALIDATE:

web3/types.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666
Timestamp = NewType("Timestamp", int)
6767
Wei = NewType("Wei", int)
6868
Gwei = NewType("Gwei", int)
69-
Formatters = Dict[RPCEndpoint, Callable[..., Any]]
69+
RequestFormatter = Callable[..., TReturn]
70+
RequestFormatters = Dict[RPCEndpoint, RequestFormatter[Any]]
71+
ResponseFormatter = Callable[["RPCResponse"], TReturn]
72+
ResponseFormatters = Dict[RPCEndpoint, ResponseFormatter[Any]]
7073

7174

7275
class AccessListEntry(TypedDict):
@@ -308,9 +311,9 @@ class CreateAccessListResponse(TypedDict):
308311

309312

310313
class FormattersDict(TypedDict, total=False):
311-
error_formatters: Optional[Formatters]
312-
request_formatters: Optional[Formatters]
313-
result_formatters: Optional[Formatters]
314+
error_formatters: Optional[ResponseFormatters]
315+
request_formatters: Optional[ResponseFormatters]
316+
result_formatters: Optional[ResponseFormatters]
314317

315318

316319
class FilterParams(TypedDict, total=False):

0 commit comments

Comments
 (0)