Skip to content

Commit

Permalink
🔖 version 1.7.19
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Aug 22, 2023
1 parent 43d42e2 commit f6c2d4d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# 更新日志

## Alconna 1.7.19

### 新增:
- 加入 `UnpackVar`,其接受 `dataclass` 并转为 Args,将解析结果构造为 dcls 实例
- 增加 `Arparma.addition` 类方法,用来为 `Arparma.call` 增加额外参数的工厂函数

### 改进:
- `Arparma.query` 改用描述器实现,并支持如 `arp.query[int]("foo.bar")` 的语法,以替代原先的 `query_with` (query_with 方法仍然保留)
- `Arparma[...]` 增加如 `arp[int, 2]` 的支持,即选择第 i 个匹配类型的参数

## Alconna 1.7.18

### 新增:
`ShortcutArgs` 加入一个 `prefix: bool` 参数,控制快捷指令是否保留源指令的前缀
- `ShortcutArgs` 加入一个 `prefix: bool` 参数,控制快捷指令是否保留源指令的前缀

## Alconna 1.7.17

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 @@ -49,7 +49,7 @@
from .typing import UnpackVar as UnpackVar
from .typing import Up as Up

__version__ = "1.7.18"
__version__ = "1.7.19"

# backward compatibility
Arpamar = Arparma
Expand Down
9 changes: 4 additions & 5 deletions src/arclet/alconna/arparma.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(
self.subcommands = subcommands or {}

_additional: ClassVar[dict[str, Callable[[], Any]]] = {}
query = _Query[Any]()

def _clr(self):
ks = list(self.__dict__.keys())
Expand Down Expand Up @@ -249,8 +250,8 @@ def call(self, target: Callable[..., T]) -> T:
pos_args = []
kw_args = {}
data = {
**self.all_matched_args,
**{k: v() for k, v in self._additional.items()},
**self.all_matched_args,
"all_args": self.all_matched_args,
"options": self.options,
"subcommands": self.subcommands
Expand Down Expand Up @@ -293,7 +294,7 @@ def __require__(self, parts: list[str]) -> tuple[dict[str, Any] | OptionResult |
return getattr(self, prefix, {}), parts.pop(0)
return None, prefix

query = _Query[Any]()
def query_with(self, arg_type: type[T], *args): return self.query[arg_type](*args)

def find(self, path: str) -> bool:
"""查询路径是否存在
Expand Down Expand Up @@ -334,9 +335,7 @@ def __getitem__(self, item: str | type[T] | tuple[type[T], int]) -> T | Any | No
if isinstance(item, str):
return self.query(item)
if isinstance(item, tuple):
return [
i for i in self.all_matched_args.values() if generic_isinstance(i, item[0])
][item[1]]
return [i for i in self.all_matched_args.values() if generic_isinstance(i, item[0])][item[1]]
return next(i for i in self.all_matched_args.values() if generic_isinstance(i, item))

def __getattr__(self, item: str):
Expand Down

0 comments on commit f6c2d4d

Please sign in to comment.