Skip to content

Commit

Permalink
🐛 version 1.8.14
Browse files Browse the repository at this point in the history
fix data in shortcut
  • Loading branch information
RF-Tar-Railt committed Jun 2, 2024
1 parent 0f877d6 commit 28171cf
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## Alconna 1.8.14

### 修复

- 修复 `shortcut` 错误处理非字符串参数的问题

## Alconna 1.8.13

### 改进
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/arclet/alconna/_internal/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/arclet/alconna/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 4 additions & 2 deletions src/arclet/alconna/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 = {}
Expand Down
2 changes: 1 addition & 1 deletion tests/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 28171cf

Please sign in to comment.