diff --git a/CHANGELOG.md b/CHANGELOG.md index d9dc90b0..633a52ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +## Alconna 1.8.14 + +### 修复 + +- 修复 `shortcut` 错误处理非字符串参数的问题 + ## Alconna 1.8.13 ### 改进 diff --git a/src/arclet/alconna/__init__.py b/src/arclet/alconna/__init__.py index bde13ff1..74f1e7ff 100644 --- a/src/arclet/alconna/__init__.py +++ b/src/arclet/alconna/__init__.py @@ -51,7 +51,7 @@ from .typing import UnpackVar as UnpackVar from .typing import Up as Up -__version__ = "1.8.13" +__version__ = "1.8.14" # backward compatibility AnyOne = ANY diff --git a/src/arclet/alconna/_internal/_handlers.py b/src/arclet/alconna/_internal/_handlers.py index c77c8752..ec9ef41d 100644 --- a/src/arclet/alconna/_internal/_handlers.py +++ b/src/arclet/alconna/_internal/_handlers.py @@ -708,8 +708,8 @@ def _handle_shortcut_data(argv: Argv, data: list): data.clear() break - def recover_quote(_unit: str): - if any(_unit.count(sep) for sep in argv.separators) and not (_unit[0] in ('"', "'") and _unit[0] == _unit[-1]): + def recover_quote(_unit): + if isinstance(_unit, str) and any(_unit.count(sep) for sep in argv.separators) and not (_unit[0] in ('"', "'") and _unit[0] == _unit[-1]): return f'"{_unit}"' return _unit diff --git a/src/arclet/alconna/formatter.py b/src/arclet/alconna/formatter.py index 29e2c4f2..ae4e23de 100644 --- a/src/arclet/alconna/formatter.py +++ b/src/arclet/alconna/formatter.py @@ -285,10 +285,10 @@ def shortcut(self, shortcuts: dict[str, Any]) -> str: if isinstance(short, InnerShortcutArgs): _key = key + (" ...args" if short.fuzzy else "") prefixes = f"[{'│'.join(short.prefixes)}]" if short.prefixes else "" - result.append(f"'{prefixes}{_key}' => {prefixes}{short.command} {' '.join(short.args)}") + result.append(f"'{prefixes}{_key}' => {prefixes}{short.command} {' '.join(map(str, short.args))}") else: result.append(f"'{key}' => {short.origin!r}") return f"{lang.require('format', 'shortcuts')}:\n" + "\n".join(result) -__all__ = ["TextFormatter", "Trace"] +__all__ = ["TextFormatter", "Trace", "TraceHead"] diff --git a/src/arclet/alconna/manager.py b/src/arclet/alconna/manager.py index 87139bfa..255f2a31 100644 --- a/src/arclet/alconna/manager.py +++ b/src/arclet/alconna/manager.py @@ -33,7 +33,10 @@ class CommandManager: sign: str current_count: int - max_count: int + + @property + def max_count(self) -> int: + return config.command_max_count __commands: dict[str, WeakValueDictionary[str, Alconna]] __analysers: WeakKeyDictionary[Alconna, Analyser] @@ -45,7 +48,6 @@ class CommandManager: def __init__(self): self.cache_path = f"{__file__.replace('manager.py', '')}manager_cache.db" self.sign = "ALCONNA::" - self.max_count = config.command_max_count self.current_count = 0 self.__commands = {} diff --git a/tests/core_test.py b/tests/core_test.py index e5464b20..4844df26 100644 --- a/tests/core_test.py +++ b/tests/core_test.py @@ -548,7 +548,7 @@ def wrapper(slot, content): alc16_10 = Alconna("core16_10", Args["bar", str]["baz", int]) alc16_10.shortcut("/qux", {"command": "core16_10"}) - assert alc16_10.parse('/qux "abc def.zip" 123').bar == "abc def.zip" + assert alc16_10.parse(['/qux "abc def.zip"', 123]).bar == "abc def.zip" def test_help():