Skip to content

Commit 7992eb0

Browse files
committed
feat: cache Method.method_selector_fn
1 parent 7c084e0 commit 7992eb0

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

newsfragments/3696.performance.rst

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

web3/method.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ def __get__(
179179
def __call__(self, *args: Any, **kwargs: Any) -> Any:
180180
return self.__get__(self._module)(*args, **kwargs)
181181

182-
@property
182+
@functools.cached_property
183183
def method_selector_fn(
184184
self,
185-
) -> Callable[..., Union[RPCEndpoint, Callable[..., RPCEndpoint]]]:
185+
) -> Callable[[], RPCEndpoint]:
186186
"""Gets the method selector from the config."""
187187
if callable(self.json_rpc_method):
188188
return self.json_rpc_method
189189
elif isinstance(self.json_rpc_method, (str,)):
190-
return lambda *_: self.json_rpc_method
190+
return lambda: self.json_rpc_method
191191
raise Web3ValueError(
192192
"``json_rpc_method`` config invalid. May be a string or function"
193193
)

0 commit comments

Comments
 (0)