Skip to content

Commit

Permalink
🚨 fix linting warning (rule B019)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRomanovizc authored and pacrob committed Feb 28, 2024
1 parent abbe210 commit 2367eef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions eth_abi/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class NodeVisitor(parsimonious.NodeVisitor): # type: ignore[misc] # subclasses
post-processing of parse trees. Parsing operations are cached.
"""

def __init__(self):
self.parse = functools.lru_cache(maxsize=None)(self._parse_uncached)

grammar = grammar

def visit_non_zero_tuple(self, node, visited_children):
Expand Down Expand Up @@ -103,8 +106,7 @@ def generic_visit(self, node, visited_children):

return tuple(visited_children)

@functools.lru_cache(maxsize=None) # noqa: B019
def parse(self, type_str, **kwargs):
def _parse_uncached(self, type_str, **kwargs):
"""
Parses a type string into an appropriate instance of
:class:`~eth_abi.grammar.ABIType`. If a type string cannot be parsed,
Expand Down
8 changes: 4 additions & 4 deletions eth_abi/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ class ABIRegistry(Copyable, BaseRegistry):
def __init__(self):
self._encoders = PredicateMapping("encoder registry")
self._decoders = PredicateMapping("decoder registry")
self.get_encoder = functools.lru_cache(maxsize=None)(self._get_encoder_uncached)
self.get_decoder = functools.lru_cache(maxsize=None)(self._get_decoder_uncached)

def _get_registration(self, mapping, type_str):
coder = super()._get_registration(mapping, type_str)
Expand Down Expand Up @@ -451,8 +453,7 @@ def unregister(self, label: Optional[str]) -> None:
self.unregister_encoder(label)
self.unregister_decoder(label)

@functools.lru_cache(maxsize=None) # noqa: B019
def get_encoder(self, type_str):
def _get_encoder_uncached(self, type_str):
return self._get_registration(self._encoders, type_str)

def has_encoder(self, type_str: abi.TypeStr) -> bool:
Expand All @@ -471,8 +472,7 @@ def has_encoder(self, type_str: abi.TypeStr) -> bool:

return True

@functools.lru_cache(maxsize=None) # noqa: B019
def get_decoder(self, type_str, strict=True):
def _get_decoder_uncached(self, type_str, strict=True):
decoder = self._get_registration(self._decoders, type_str)

if hasattr(decoder, "is_dynamic") and decoder.is_dynamic:
Expand Down

0 comments on commit 2367eef

Please sign in to comment.