From 6ee17ebf2db68afb383bcdd3252dbc565989c0b5 Mon Sep 17 00:00:00 2001 From: Tarrailt Date: Thu, 8 Feb 2024 10:48:33 +0000 Subject: [PATCH] :bug: fix typing --- src/arclet/alconna/arparma.py | 4 ++-- src/arclet/alconna/base.py | 2 +- src/arclet/alconna/builtin.py | 2 +- tests/analyser_test.py | 6 +++++- tests/config_test.py | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/arclet/alconna/arparma.py b/src/arclet/alconna/arparma.py index cd350733..7bbb8faa 100644 --- a/src/arclet/alconna/arparma.py +++ b/src/arclet/alconna/arparma.py @@ -278,9 +278,9 @@ def call(self, target: Callable[..., T]) -> T: bind.apply_defaults() return target(*bind.args, **bind.kwargs) - def fail(self, exc: type[Exception] | Exception): + def fail(self, exc: type[Exception] | Exception) -> Self: """生成一个失败的 `Arparma`""" - return Arparma(self.source, self.origin, False, self.header_match, error_info=exc) + return Arparma(self.source, self.origin, False, self.header_match, error_info=exc) # type: ignore def __require__(self, parts: list[str]) -> tuple[dict[str, Any] | OptionResult | SubcommandResult | None, str]: """如果能够返回, 除开基本信息, 一定返回该path所在的dict""" diff --git a/src/arclet/alconna/base.py b/src/arclet/alconna/base.py index 3c55d51e..d0a17bb5 100644 --- a/src/arclet/alconna/base.py +++ b/src/arclet/alconna/base.py @@ -210,7 +210,7 @@ def __add__(self, other: Option) -> Subcommand: def __add__(self, other: Args | Arg) -> Option: ... - def __add__(self, other: Option | Args | Arg) -> Self | Subcommand: + def __add__(self, other: Option | Args | Arg) -> Subcommand | Option: """连接命令选项与命令节点或命令选项, 生成子命令 Args: diff --git a/src/arclet/alconna/builtin.py b/src/arclet/alconna/builtin.py index 779c10f1..d3849d05 100644 --- a/src/arclet/alconna/builtin.py +++ b/src/arclet/alconna/builtin.py @@ -84,7 +84,7 @@ def set_default( def set_default( *, value: Any = MISSING, - factory: Callable[..., Any] = MISSING, + factory: Callable[..., Any] | _MISSING_TYPE = MISSING, path: str | None = None, ) -> _SetDefault: """ diff --git a/tests/analyser_test.py b/tests/analyser_test.py index ae75f127..da971adb 100644 --- a/tests/analyser_test.py +++ b/tests/analyser_test.py @@ -33,7 +33,11 @@ def at(user_id: Union[int, str]): def gen_unit(type_: str): return BasePattern( - type_, MatchMode.TYPE_CONVERT, Any, lambda _, seg: seg if seg.type == type_ else None, type_, accepts=[Segment] + model=MatchMode.TYPE_CONVERT, + origin=Any, + converter=lambda _, seg: seg if seg.type == type_ else None, + alias=type_, + accepts=[Segment] ) diff --git a/tests/config_test.py b/tests/config_test.py index 0f3f11a9..7799d631 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -3,7 +3,7 @@ def test_config(): with namespace("cfg1") as np: - np.separators = {";"} + np.separators = (";",) cfg = Alconna("cfg") + Option("foo") assert cfg.parse("cfg foo").matched is False assert cfg.parse("cfg;foo").matched is True