Skip to content

Commit 39da1f6

Browse files
CopilotSigureMo
andauthored
refactor: type subparser protocol
Agent-Logs-Url: https://github.com/ShigureLab/expr-simplifier/sessions/8d74859a-e701-4f8a-97bc-3e7d404c7baa Co-authored-by: SigureMo <38436475+SigureMo@users.noreply.github.com>
1 parent ac3a4e3 commit 39da1f6

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/expr_simplifier/__main__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
import argparse
44
import ast
55
from collections.abc import Callable
6-
from typing import Any
6+
from typing import Any, Protocol
77

88
from expr_simplifier import __version__
99
from expr_simplifier.transforms import apply_constant_folding, apply_cse, apply_logical_simplification
1010
from expr_simplifier.typing import Pass
1111
from expr_simplifier.utils import loop_until_stable
1212

1313

14+
class _SubparserFactory(Protocol):
15+
def add_parser(self, name: str, /, **kwargs: Any) -> argparse.ArgumentParser: ...
16+
17+
1418
def create_pass_command(name: str, passes: list[Pass]) -> Callable[[argparse.Namespace], None]:
1519
def pass_command(args: argparse.Namespace) -> None:
1620
expr = ast.parse(args.input, mode="eval")
@@ -25,7 +29,7 @@ def create_pass_parser(
2529
name: str,
2630
passes: list[Pass],
2731
description: str,
28-
subparser: Any,
32+
subparser: _SubparserFactory,
2933
) -> None:
3034
parser = subparser.add_parser(name, help=description)
3135
parser.add_argument("input", help="The expression to simplify")

0 commit comments

Comments
 (0)