Skip to content

Commit 6a2b18b

Browse files
committed
🐛 version 1.7.44
fix shortcut_list
1 parent e00aa85 commit 6a2b18b

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# 更新日志
22

3+
## Alconna 1.7.44
4+
5+
### 修复
6+
7+
- 修复 `shortcut list` 的错误
8+
39
## Alconna 1.7.43
410

511
### 改进

src/arclet/alconna/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from .typing import UnpackVar as UnpackVar
5151
from .typing import Up as Up
5252

53-
__version__ = "1.7.43"
53+
__version__ = "1.7.44"
5454

5555
# backward compatibility
5656
Arpamar = Arparma

src/arclet/alconna/core.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from typing import Any, Callable, Generic, Literal, Sequence, TypeVar, cast, overload
99
from typing_extensions import Self
10-
10+
from weakref import WeakSet
1111
from tarina import init_spec, lang
1212

1313
from ._internal._analyser import Analyser, TCompile
@@ -169,7 +169,8 @@ def __init__(
169169
self.behaviors.extend(requirement_handler(behavior))
170170
command_manager.register(self)
171171
self._executors: dict[ArparmaExecutor, Any] = {}
172-
self.union = set()
172+
self.union: "WeakSet[Alconna]" = WeakSet()
173+
self._union = False
173174

174175
@property
175176
def namespace_config(self) -> Namespace:
@@ -346,8 +347,8 @@ def subcommand(self, sub: Subcommand) -> Self:
346347
return self.add(sub)
347348

348349
def _parse(self, message: TDC) -> Arparma[TDC]:
349-
if self.union:
350-
for ana, argv in command_manager.requires(*self.union):
350+
if self._union:
351+
for ana, argv in command_manager.unpack(self.union):
351352
if (res := ana.process(argv.build(message))).matched:
352353
return res
353354
analyser = command_manager.require(self)
@@ -429,7 +430,8 @@ def __add__(self, other) -> Self:
429430
return self
430431

431432
def __or__(self, other: Alconna) -> Self:
432-
self.union.add(other.path)
433+
self.union.add(other)
434+
self._union = True
433435
return self
434436

435437
def _calc_hash(self):

src/arclet/alconna/manager.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ def require(self, command: Alconna[TDC]) -> Analyser[TDC]:
152152
namespace, name = self._command_part(command.path)
153153
raise ValueError(lang.require("manager", "undefined_command").format(target=f"{namespace}.{name}")) from e
154154

155-
def requires(self, *paths: str) -> zip[tuple[Analyser, Argv]]: # type: ignore
155+
def unpack(self, commands: set[Alconna]) -> zip[tuple[Analyser, Argv]]: # type: ignore
156156
"""获取多个命令解析器"""
157157
return zip(
158-
[v for k, v in self.__analysers.items() if k.path in paths],
159-
[v for k, v in self.__argv.items() if k.path in paths],
158+
[v for k, v in self.__analysers.items() if k in commands],
159+
[v for k, v in self.__argv.items() if k in commands],
160160
)
161161

162162
def delete(self, command: Alconna | str) -> None:
@@ -230,7 +230,7 @@ def get_shortcut(self, target: Alconna[TDC]) -> dict[str, Union[Arparma[TDC], In
230230
dict[str, Arparma | InnerShortcutArgs]: 快捷命令的参数
231231
"""
232232
namespace, name = self._command_part(target.path)
233-
if f"{namespace}.{name}" not in self.__analysers:
233+
if f"{namespace}.{name}" not in self.__shortcuts:
234234
raise ValueError(lang.require("manager", "undefined_command").format(target=f"{namespace}.{name}"))
235235
if not (_shortcut := self.__shortcuts.get(f"{namespace}.{name}")):
236236
return {}

0 commit comments

Comments
 (0)