Skip to content

Commit 2a21a0f

Browse files
author
pacrob
committed
use module.is_async instead of adding method async flag
1 parent ec63100 commit 2a21a0f

File tree

4 files changed

+13
-27
lines changed

4 files changed

+13
-27
lines changed

tests/core/method-class/test_result_formatters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020

2121

22-
def result_formatter(method, module, is_async):
22+
def result_formatter(method, module):
2323
def formatter(self):
2424
return "OKAY"
2525

web3/_utils/method_formatters.py

+11-21
Original file line numberDiff line numberDiff line change
@@ -769,19 +769,21 @@ def filter_wrapper(
769769
]:
770770
if method == RPC.eth_newBlockFilter:
771771
if module.is_async:
772-
return AsyncBlockFilter(filter_id, eth_module=cast(AsyncEth, module))
772+
return AsyncBlockFilter(filter_id, eth_module=cast("AsyncEth", module))
773773
else:
774-
return BlockFilter(filter_id, eth_module=cast(Eth, module))
774+
return BlockFilter(filter_id, eth_module=cast("Eth", module))
775775
elif method == RPC.eth_newPendingTransactionFilter:
776776
if module.is_async:
777-
return AsyncTransactionFilter(filter_id, eth_module=cast(AsyncEth, module))
777+
return AsyncTransactionFilter(
778+
filter_id, eth_module=cast("AsyncEth", module)
779+
)
778780
else:
779-
return TransactionFilter(filter_id, eth_module=cast(Eth, module))
781+
return TransactionFilter(filter_id, eth_module=cast("Eth", module))
780782
elif method == RPC.eth_newFilter:
781783
if module.is_async:
782-
return AsyncLogFilter(filter_id, eth_module=cast(AsyncEth, module))
784+
return AsyncLogFilter(filter_id, eth_module=cast("AsyncEth", module))
783785
else:
784-
return LogFilter(filter_id, eth_module=cast(Eth, module))
786+
return LogFilter(filter_id, eth_module=cast("Eth", module))
785787
else:
786788
raise NotImplementedError(
787789
"Filter wrapper needs to be used with either "
@@ -796,12 +798,6 @@ def filter_wrapper(
796798
RPC.eth_newFilter: filter_wrapper,
797799
}
798800

799-
ASYNC_FILTER_RESULT_FORMATTERS: Dict[RPCEndpoint, Callable[..., Any]] = {
800-
RPC.eth_newPendingTransactionFilter: filter_wrapper,
801-
RPC.eth_newBlockFilter: filter_wrapper,
802-
RPC.eth_newFilter: filter_wrapper,
803-
}
804-
805801

806802
@to_tuple
807803
def apply_module_to_formatters(
@@ -816,18 +812,12 @@ def apply_module_to_formatters(
816812
def get_result_formatters(
817813
method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]],
818814
module: "Module",
819-
is_async: bool = False,
820815
) -> Dict[str, Callable[..., Any]]:
821816
formatters = combine_formatters((PYTHONIC_RESULT_FORMATTERS,), method_name)
822817

823-
if is_async:
824-
formatters_requiring_module = combine_formatters(
825-
(ASYNC_FILTER_RESULT_FORMATTERS,), method_name
826-
)
827-
else:
828-
formatters_requiring_module = combine_formatters(
829-
(FILTER_RESULT_FORMATTERS,), method_name
830-
)
818+
formatters_requiring_module = combine_formatters(
819+
(FILTER_RESULT_FORMATTERS,), method_name
820+
)
831821

832822
partial_formatters = apply_module_to_formatters(
833823
formatters_requiring_module, module, method_name

web3/eth.py

-2
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,6 @@ async def get_storage_at(
633633
if_new_filter=RPC.eth_newFilter,
634634
),
635635
mungers=[BaseEth.filter_munger],
636-
is_async=True,
637636
)
638637

639638
async def filter(
@@ -976,7 +975,6 @@ def fee_history(
976975
if_new_filter=RPC.eth_newFilter,
977976
),
978977
mungers=[BaseEth.filter_munger],
979-
is_async=False,
980978
)
981979

982980
get_filter_changes: Method[Callable[[HexStr], List[LogReceipt]]] = Method(

web3/method.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ def __init__(
142142
null_result_formatters: Optional[Callable[..., TReturn]] = None,
143143
method_choice_depends_on_args: Optional[Callable[..., RPCEndpoint]] = None,
144144
is_property: bool = False,
145-
is_async: bool = False,
146145
):
147146
self.json_rpc_method = json_rpc_method
148147
self.mungers = _set_mungers(mungers, is_property)
@@ -153,7 +152,6 @@ def __init__(
153152
)
154153
self.method_choice_depends_on_args = method_choice_depends_on_args
155154
self.is_property = is_property
156-
self.is_async = is_async
157155

158156
def __get__(
159157
self, obj: Optional["Module"] = None, obj_type: Optional[Type["Module"]] = None
@@ -226,7 +224,7 @@ def process_params(
226224

227225
method = self.method_selector_fn()
228226
response_formatters = (
229-
self.result_formatters(method, module, self.is_async),
227+
self.result_formatters(method, module),
230228
get_error_formatters(method),
231229
self.null_result_formatters(method),
232230
)

0 commit comments

Comments
 (0)