Skip to content

Commit

Permalink
CHIA-2222 Annotate analyze-chain.py (#19143)
Browse files Browse the repository at this point in the history
Annotate analyze-chain.py.
  • Loading branch information
AmineKhaldi authored Jan 27, 2025
1 parent 9aefa01 commit 0df990a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion mypy-exclusions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,3 @@ chia._tests.util.test_misc
chia._tests.util.time_out_assert
chia._tests.wallet.did_wallet.test_did
chia._tests.wallet.rpc.test_wallet_rpc
tools.analyze-chain
16 changes: 12 additions & 4 deletions tools/analyze-chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from functools import partial
from pathlib import Path
from time import time
from typing import Callable, Optional, Union
from typing import Callable, Optional, Union, cast

import click
import zstd
Expand Down Expand Up @@ -55,10 +55,16 @@ def run_gen(
return 117, None, 0


def callable_for_module_function_path(call: str) -> Callable:
def callable_for_module_function_path(
call: str,
) -> Callable[[Union[BlockInfo, FullBlock], bytes32, int, list[bytes], float, int], None]:
module_name, function_name = call.split(":", 1)
module = __import__(module_name, fromlist=[function_name])
return getattr(module, function_name)
# TODO: casting due to getattr type signature
return cast(
Callable[[Union[BlockInfo, FullBlock], bytes32, int, list[bytes], float, int], None],
getattr(module, function_name),
)


@click.command()
Expand All @@ -70,7 +76,9 @@ def callable_for_module_function_path(call: str) -> Callable:
@click.option("--start", default=225000, help="first block to examine")
@click.option("--end", default=None, help="last block to examine")
@click.option("--call", default=None, help="function to pass block iterator to in form `module:function`")
def main(file: Path, mempool_mode: bool, start: int, end: Optional[int], call: Optional[str], verify_signatures: bool):
def main(
file: Path, mempool_mode: bool, start: int, end: Optional[int], call: Optional[str], verify_signatures: bool
) -> None:
call_f: Callable[[Union[BlockInfo, FullBlock], bytes32, int, list[bytes], float, int], None]
if call is None:
call_f = partial(default_call, verify_signatures)
Expand Down

0 comments on commit 0df990a

Please sign in to comment.