From 0953bc50226ef8b1885a1c75db802d0cecfccb84 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Sat, 17 May 2025 15:51:29 -0400 Subject: [PATCH 1/6] feat: optimize apply_formatter_at_index --- eth_utils/applicators.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/eth_utils/applicators.py b/eth_utils/applicators.py index 9bfd5939..4bc8dd20 100644 --- a/eth_utils/applicators.py +++ b/eth_utils/applicators.py @@ -30,16 +30,18 @@ def apply_formatter_at_index( formatter: Callable[..., Any], at_index: int, value: List[Any] ) -> Generator[List[Any], None, None]: - if at_index + 1 > len(value): + try: + item = value[at_index] + except IndexError: raise IndexError( f"Not enough values in iterable to apply formatter. Got: {len(value)}. " f"Need: {at_index + 1}" ) - for index, item in enumerate(value): - if index == at_index: - yield formatter(item) - else: - yield item + + yield from value[:at_index] + yield formatter(item) + if remaining := value[at_index+1:]: + yield from remaining def combine_argument_formatters(*formatters: List[Callable[..., Any]]) -> Formatters: From bf0fb110d5df33d67edc6321e0a387ad3ba24461 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Sat, 17 May 2025 17:06:52 -0400 Subject: [PATCH 2/6] chore: lint --- eth_utils/applicators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth_utils/applicators.py b/eth_utils/applicators.py index 4bc8dd20..a58941eb 100644 --- a/eth_utils/applicators.py +++ b/eth_utils/applicators.py @@ -40,7 +40,7 @@ def apply_formatter_at_index( yield from value[:at_index] yield formatter(item) - if remaining := value[at_index+1:]: + if remaining := value[at_index + 1 :]: yield from remaining From 56b859ac10abc84457a632b3f463a064b5844fe1 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Sat, 17 May 2025 17:08:04 -0400 Subject: [PATCH 3/6] Update applicators.py --- eth_utils/applicators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth_utils/applicators.py b/eth_utils/applicators.py index a58941eb..a250dc06 100644 --- a/eth_utils/applicators.py +++ b/eth_utils/applicators.py @@ -36,7 +36,7 @@ def apply_formatter_at_index( raise IndexError( f"Not enough values in iterable to apply formatter. Got: {len(value)}. " f"Need: {at_index + 1}" - ) + ) from None yield from value[:at_index] yield formatter(item) From c90ac8f825568a82f67983ba6e2b30bfaed30a9e Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Mon, 19 May 2025 14:08:15 -0400 Subject: [PATCH 4/6] Create 306.performance.rst --- newsfragments/306.performance.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/306.performance.rst diff --git a/newsfragments/306.performance.rst b/newsfragments/306.performance.rst new file mode 100644 index 00000000..1b08a297 --- /dev/null +++ b/newsfragments/306.performance.rst @@ -0,0 +1 @@ +optimize apply_formatter_at_index From dcd8037ee0964e495cb88a899b2011e6763b2e1e Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Mon, 19 May 2025 14:29:28 -0400 Subject: [PATCH 5/6] Update applicators.py --- eth_utils/applicators.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eth_utils/applicators.py b/eth_utils/applicators.py index a250dc06..86ef5f2a 100644 --- a/eth_utils/applicators.py +++ b/eth_utils/applicators.py @@ -40,8 +40,7 @@ def apply_formatter_at_index( yield from value[:at_index] yield formatter(item) - if remaining := value[at_index + 1 :]: - yield from remaining + yield from value[at_index + 1 :] def combine_argument_formatters(*formatters: List[Callable[..., Any]]) -> Formatters: From 67bfe3980da6034e7711530ec99c75e359c728ac Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Sun, 5 Oct 2025 03:05:16 -0400 Subject: [PATCH 6/6] Update applicators.py --- eth_utils/applicators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eth_utils/applicators.py b/eth_utils/applicators.py index 86ef5f2a..5cb3e91f 100644 --- a/eth_utils/applicators.py +++ b/eth_utils/applicators.py @@ -28,8 +28,8 @@ @return_arg_type(2) def apply_formatter_at_index( - formatter: Callable[..., Any], at_index: int, value: List[Any] -) -> Generator[List[Any], None, None]: + formatter: Callable[..., Any], at_index: int, value: Sequence[Any] +) -> Generator[Any, None, None]: try: item = value[at_index] except IndexError: