Skip to content

Commit 81a1249

Browse files
committed
Make if statement generic in result_formatters
1 parent 017f24d commit 81a1249

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

web3/_utils/method_formatters.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,12 @@ def filter_wrapper(
618618
}
619619

620620

621+
@to_tuple
622+
def partially_applied_formatters(formatters, module, method_name):
623+
for f in formatters:
624+
yield partial(f, module, method_name)
625+
626+
621627
def get_result_formatters(
622628
method_name: Union[RPCEndpoint, Callable[..., RPCEndpoint]],
623629
module: Union["Module", "ModuleV2"],
@@ -626,17 +632,14 @@ def get_result_formatters(
626632
(PYTHONIC_RESULT_FORMATTERS,),
627633
method_name
628634
)
629-
filter_formatters = combine_formatters(
635+
formatters_requiring_module = combine_formatters(
630636
(FILTER_RESULT_FORMATTERS,),
631637
method_name
632638
)
633639

640+
partial_formatters = partially_applied_formatters(formatters_requiring_module, module, method_name)
634641
attrdict_formatter = apply_formatter_if(is_dict and not_attrdict, AttributeDict.recursive)
635-
if filter_formatters:
636-
partial_filter_formatters = partial(filter_formatters[0], module, method_name)
637-
return compose(partial_filter_formatters, attrdict_formatter, *formatters)
638-
else:
639-
return compose(attrdict_formatter, *formatters)
642+
return compose(*partial_formatters, attrdict_formatter, *formatters)
640643

641644

642645
def get_error_formatters(

0 commit comments

Comments
 (0)