Skip to content

Commit 51b76f1

Browse files
feat: microoptimize Method.method_selector_fn (#3696)
1 parent ed01430 commit 51b76f1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

newsfragments/3696.performance.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
optimize Method.method_selector_function

web3/method.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,13 @@ def __call__(self, *args: Any, **kwargs: Any) -> Any:
182182
@property
183183
def method_selector_fn(
184184
self,
185-
) -> Callable[..., RPCEndpoint]:
185+
) -> Callable[[], RPCEndpoint]:
186186
"""Gets the method selector from the config."""
187-
if callable(self.json_rpc_method):
188-
return self.json_rpc_method
189-
elif isinstance(self.json_rpc_method, (str,)):
190-
return lambda *_: self.json_rpc_method
187+
method = self.json_rpc_method
188+
if callable(method):
189+
return method
190+
elif isinstance(method, str):
191+
return lambda: method
191192
raise Web3ValueError(
192193
"``json_rpc_method`` config invalid. May be a string or function"
193194
)

0 commit comments

Comments
 (0)