Skip to content

Commit

Permalink
use module.is_async instead of adding method async flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pacrob committed Sep 14, 2022
1 parent 52c0cd9 commit 3cf4b51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
32 changes: 11 additions & 21 deletions web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,19 +769,21 @@ def filter_wrapper(
]:
if method == RPC.eth_newBlockFilter:
if module.is_async:
return AsyncBlockFilter(filter_id, eth_module=cast(AsyncEth, module))
return AsyncBlockFilter(filter_id, eth_module=cast("AsyncEth", module))
else:
return BlockFilter(filter_id, eth_module=cast(Eth, module))
return BlockFilter(filter_id, eth_module=cast("Eth", module))
elif method == RPC.eth_newPendingTransactionFilter:
if module.is_async:
return AsyncTransactionFilter(filter_id, eth_module=cast(AsyncEth, module))
return AsyncTransactionFilter(
filter_id, eth_module=cast("AsyncEth", module)
)
else:
return TransactionFilter(filter_id, eth_module=cast(Eth, module))
return TransactionFilter(filter_id, eth_module=cast("Eth", module))
elif method == RPC.eth_newFilter:
if module.is_async:
return AsyncLogFilter(filter_id, eth_module=cast(AsyncEth, module))
return AsyncLogFilter(filter_id, eth_module=cast("AsyncEth", module))
else:
return LogFilter(filter_id, eth_module=cast(Eth, module))
return LogFilter(filter_id, eth_module=cast("Eth", module))
else:
raise NotImplementedError(
"Filter wrapper needs to be used with either "
Expand All @@ -796,12 +798,6 @@ def filter_wrapper(
RPC.eth_newFilter: filter_wrapper,
}

ASYNC_FILTER_RESULT_FORMATTERS: Dict[RPCEndpoint, Callable[..., Any]] = {
RPC.eth_newPendingTransactionFilter: filter_wrapper,
RPC.eth_newBlockFilter: filter_wrapper,
RPC.eth_newFilter: filter_wrapper,
}


@to_tuple
def apply_module_to_formatters(
Expand All @@ -816,18 +812,12 @@ def apply_module_to_formatters(
def get_result_formatters(
method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]],
module: "Module",
is_async: bool = False,
) -> Dict[str, Callable[..., Any]]:
formatters = combine_formatters((PYTHONIC_RESULT_FORMATTERS,), method_name)

if is_async:
formatters_requiring_module = combine_formatters(
(ASYNC_FILTER_RESULT_FORMATTERS,), method_name
)
else:
formatters_requiring_module = combine_formatters(
(FILTER_RESULT_FORMATTERS,), method_name
)
formatters_requiring_module = combine_formatters(
(FILTER_RESULT_FORMATTERS,), method_name
)

partial_formatters = apply_module_to_formatters(
formatters_requiring_module, module, method_name
Expand Down
2 changes: 0 additions & 2 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ async def get_storage_at(
if_new_filter=RPC.eth_newFilter,
),
mungers=[BaseEth.filter_munger],
is_async=True,
)

async def filter(
Expand Down Expand Up @@ -976,7 +975,6 @@ def fee_history(
if_new_filter=RPC.eth_newFilter,
),
mungers=[BaseEth.filter_munger],
is_async=False,
)

get_filter_changes: Method[Callable[[HexStr], List[LogReceipt]]] = Method(
Expand Down
4 changes: 1 addition & 3 deletions web3/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def __init__(
null_result_formatters: Optional[Callable[..., TReturn]] = None,
method_choice_depends_on_args: Optional[Callable[..., RPCEndpoint]] = None,
is_property: bool = False,
is_async: bool = False,
):
self.json_rpc_method = json_rpc_method
self.mungers = _set_mungers(mungers, is_property)
Expand All @@ -153,7 +152,6 @@ def __init__(
)
self.method_choice_depends_on_args = method_choice_depends_on_args
self.is_property = is_property
self.is_async = is_async

def __get__(
self, obj: Optional["Module"] = None, obj_type: Optional[Type["Module"]] = None
Expand Down Expand Up @@ -226,7 +224,7 @@ def process_params(

method = self.method_selector_fn()
response_formatters = (
self.result_formatters(method, module, self.is_async),
self.result_formatters(method, module),
get_error_formatters(method),
self.null_result_formatters(method),
)
Expand Down

0 comments on commit 3cf4b51

Please sign in to comment.