From 84600834085465e799b444601238894529b271eb Mon Sep 17 00:00:00 2001 From: Lev Gorodetskiy Date: Thu, 23 Jan 2025 12:41:18 -0300 Subject: [PATCH] tuple[MatchedHandler, ...] --- docs/9.release-notes/3.v8.0.md | 2 +- src/demo_blank/handlers/batch.py | 3 +-- src/demo_evm_events/handlers/batch.py | 3 +-- src/demo_evm_transactions/handlers/batch.py | 3 +-- src/demo_evm_uniswap/handlers/batch.py | 3 +-- src/demo_starknet_events/handlers/batch.py | 3 +-- src/demo_substrate_events/handlers/batch.py | 3 +-- src/demo_tezos_auction/handlers/batch.py | 3 +-- src/demo_tezos_dao/handlers/batch.py | 3 +-- src/demo_tezos_dex/handlers/batch.py | 3 +-- src/demo_tezos_domains/handlers/batch.py | 3 +-- src/demo_tezos_etherlink/handlers/batch.py | 3 +-- src/demo_tezos_events/handlers/batch.py | 3 +-- src/demo_tezos_factories/handlers/batch.py | 3 +-- src/demo_tezos_head/handlers/batch.py | 3 +-- src/demo_tezos_nft_marketplace/handlers/batch.py | 3 +-- src/demo_tezos_raw/handlers/batch.py | 3 +-- src/demo_tezos_token/handlers/batch.py | 3 +-- src/demo_tezos_token_balances/handlers/batch.py | 3 +-- src/demo_tezos_token_transfers/handlers/batch.py | 3 +-- src/dipdup/codegen/__init__.py | 3 +-- src/dipdup/index.py | 2 +- 22 files changed, 22 insertions(+), 42 deletions(-) diff --git a/docs/9.release-notes/3.v8.0.md b/docs/9.release-notes/3.v8.0.md index 7836185fb..487129458 100644 --- a/docs/9.release-notes/3.v8.0.md +++ b/docs/9.release-notes/3.v8.0.md @@ -65,7 +65,7 @@ DipDup 8.0 introduces a new `batch` handler to modify higher-level indexing logi ```python [handlers/batch.py] async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_blank/handlers/batch.py b/src/demo_blank/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_blank/handlers/batch.py +++ b/src/demo_blank/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_evm_events/handlers/batch.py b/src/demo_evm_events/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_evm_events/handlers/batch.py +++ b/src/demo_evm_events/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_evm_transactions/handlers/batch.py b/src/demo_evm_transactions/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_evm_transactions/handlers/batch.py +++ b/src/demo_evm_transactions/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_evm_uniswap/handlers/batch.py b/src/demo_evm_uniswap/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_evm_uniswap/handlers/batch.py +++ b/src/demo_evm_uniswap/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_starknet_events/handlers/batch.py b/src/demo_starknet_events/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_starknet_events/handlers/batch.py +++ b/src/demo_starknet_events/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_substrate_events/handlers/batch.py b/src/demo_substrate_events/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_substrate_events/handlers/batch.py +++ b/src/demo_substrate_events/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_auction/handlers/batch.py b/src/demo_tezos_auction/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_auction/handlers/batch.py +++ b/src/demo_tezos_auction/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_dao/handlers/batch.py b/src/demo_tezos_dao/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_dao/handlers/batch.py +++ b/src/demo_tezos_dao/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_dex/handlers/batch.py b/src/demo_tezos_dex/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_dex/handlers/batch.py +++ b/src/demo_tezos_dex/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_domains/handlers/batch.py b/src/demo_tezos_domains/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_domains/handlers/batch.py +++ b/src/demo_tezos_domains/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_etherlink/handlers/batch.py b/src/demo_tezos_etherlink/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_etherlink/handlers/batch.py +++ b/src/demo_tezos_etherlink/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_events/handlers/batch.py b/src/demo_tezos_events/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_events/handlers/batch.py +++ b/src/demo_tezos_events/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_factories/handlers/batch.py b/src/demo_tezos_factories/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_factories/handlers/batch.py +++ b/src/demo_tezos_factories/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_head/handlers/batch.py b/src/demo_tezos_head/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_head/handlers/batch.py +++ b/src/demo_tezos_head/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_nft_marketplace/handlers/batch.py b/src/demo_tezos_nft_marketplace/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_nft_marketplace/handlers/batch.py +++ b/src/demo_tezos_nft_marketplace/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_raw/handlers/batch.py b/src/demo_tezos_raw/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_raw/handlers/batch.py +++ b/src/demo_tezos_raw/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_token/handlers/batch.py b/src/demo_tezos_token/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_token/handlers/batch.py +++ b/src/demo_tezos_token/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_token_balances/handlers/batch.py b/src/demo_tezos_token_balances/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_token_balances/handlers/batch.py +++ b/src/demo_tezos_token_balances/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/demo_tezos_token_transfers/handlers/batch.py b/src/demo_tezos_token_transfers/handlers/batch.py index c2c321ae0..ea9e81263 100644 --- a/src/demo_tezos_token_transfers/handlers/batch.py +++ b/src/demo_tezos_token_transfers/handlers/batch.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from dipdup.context import HandlerContext from dipdup.index import MatchedHandler @@ -6,7 +5,7 @@ async def batch( ctx: HandlerContext, - handlers: Iterable[MatchedHandler], + handlers: tuple[MatchedHandler, ...], ) -> None: for handler in handlers: await ctx.fire_matched_handler(handler) diff --git a/src/dipdup/codegen/__init__.py b/src/dipdup/codegen/__init__.py index 535e79960..5ab8a1ac0 100644 --- a/src/dipdup/codegen/__init__.py +++ b/src/dipdup/codegen/__init__.py @@ -43,13 +43,12 @@ class BatchHandlerConfig(HandlerConfig, CallbackMixin): callback: str = 'batch' def iter_imports(self, package: str) -> Iterator[tuple[str, str]]: - yield 'collections.abc', 'Iterable' yield 'dipdup.context', 'HandlerContext' yield 'dipdup.index', 'MatchedHandler' def iter_arguments(self) -> Iterator[tuple[str, str]]: yield 'ctx', 'HandlerContext' - yield 'handlers', 'Iterable[MatchedHandler]' + yield 'handlers', 'tuple[MatchedHandler, ...]' class _BaseCodeGenerator(ABC): diff --git a/src/dipdup/index.py b/src/dipdup/index.py index bd5d2c4d3..aecda02ef 100644 --- a/src/dipdup/index.py +++ b/src/dipdup/index.py @@ -145,7 +145,7 @@ async def _process_level_data( return started_at = time.time() - batch_handlers = ( + batch_handlers = tuple( MatchedHandler( index=self, level=batch_level,