Skip to content

Commit

Permalink
🐛 version 1.8.23
Browse files Browse the repository at this point in the history
fix Arg's type
  • Loading branch information
RF-Tar-Railt committed Aug 6, 2024
1 parent 7aad613 commit 72d762d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 20 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# 更新日志

## 1.8.23

### 改进

- `Option` 名字设置成 `--` 时不会去除前缀

### 修复

- `Arg` 等类型参数的构造函数中的类型修复

## 1.8.22

### 修复
Expand Down
8 changes: 4 additions & 4 deletions devtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def analyse_args(
**kwargs
):
meta = CommandMeta(keep_crlf=False, fuzzy_match=False, raise_exception=raise_exception, context_style=context_style)
argv = Argv(meta, dev_space)
argv: Argv[DataCollection] = Argv(meta, dev_space)
try:
argv.enter(kwargs)
argv.build(["test"] + command)
Expand All @@ -69,7 +69,7 @@ def analyse_header(
**kwargs
):
meta = CommandMeta(keep_crlf=False, fuzzy_match=False, raise_exception=raise_exception, context_style=context_style)
argv = Argv(meta, dev_space, separators=(sep,))
argv: Argv[DataCollection] = Argv(meta, dev_space, separators=(sep,))
command_header = Header.generate(command_name, headers, compact=compact)
try:
argv.enter(kwargs)
Expand All @@ -89,7 +89,7 @@ def analyse_option(
**kwargs
):
meta = CommandMeta(keep_crlf=False, fuzzy_match=False, raise_exception=raise_exception, context_style=context_style)
argv = Argv(meta, dev_space)
argv: Argv[DataCollection] = Argv(meta, dev_space)
_analyser = _DummyAnalyser.__new__(_DummyAnalyser)
_analyser.reset()
_analyser.command.separators = (" ",)
Expand All @@ -116,7 +116,7 @@ def analyse_subcommand(
**kwargs
):
meta = CommandMeta(keep_crlf=False, fuzzy_match=False, raise_exception=raise_exception, context_style=context_style)
argv = Argv(meta, dev_space)
argv: Argv[DataCollection] = Argv(meta, dev_space)
_analyser = _DummyAnalyser.__new__(_DummyAnalyser)
_analyser.reset()
_analyser.command.separators = (" ",)
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 @@ -52,7 +52,7 @@
from .typing import Up as Up
from .typing import StrMulti as StrMulti

__version__ = "1.8.22"
__version__ = "1.8.23"

# backward compatibility
AnyOne = ANY
2 changes: 1 addition & 1 deletion src/arclet/alconna/_internal/_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def generate(
_prefixes: list[tuple[Any, str]] = prefixes # type: ignore
return cls(
(command, prefixes),
[Pair(h[0], re.compile(re.escape(h[1]) + _cmd) if to_regex else h[1] + _cmd) for h in _prefixes],
[Pair(h[0], re.compile(re.escape(h[1]) + _cmd)) if to_regex else Pair(h[0], h[1] + _cmd) for h in _prefixes],
mapping,
compact,
)
Expand Down
7 changes: 3 additions & 4 deletions src/arclet/alconna/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import sys
from enum import Enum
from functools import partial
from typing import Any, Callable, Generic, Iterable, List, Sequence, Type, TypeVar, Union, cast
from typing_extensions import Self, TypeAlias
from typing import Any, Callable, Generic, Iterable, List, Sequence, TypeVar, Union, cast
from typing_extensions import Self

from nepattern import ANY, NONE, AntiPattern, BasePattern, MatchMode, RawStr, UnionPattern, parser
from tarina import Empty, get_signature, lang

from .exceptions import InvalidArgs
from .typing import AllParam, KeyWordVar, KWBool, MultiKeyWordVar, MultiVar, UnpackVar
from .typing import TAValue, AllParam, KeyWordVar, KWBool, MultiKeyWordVar, MultiVar, UnpackVar


def safe_dcls_kw(**kwargs):
Expand All @@ -23,7 +23,6 @@ def safe_dcls_kw(**kwargs):


_T = TypeVar("_T")
TAValue: TypeAlias = Union[BasePattern[_T, Any, Any], Type[_T], str]


class ArgFlag(str, Enum):
Expand Down
3 changes: 2 additions & 1 deletion src/arclet/alconna/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def __init__(
_handle_default(self)
self.separators = (" ",) if separators is None else ((separators,) if isinstance(separators, str) else tuple(separators)) # noqa: E501
self.nargs = len(self.args.argument)
self.dest = (dest or (("_".join(self.requires) + "_") if self.requires else "") + self.name.lstrip("-")).lstrip("-") # noqa: E501
self.dest = (dest or (("_".join(self.requires) + "_") if self.requires else "") + (self.name.lstrip("-") or self.name)) # noqa: E501
self.dest = self.dest.lstrip("-") or self.dest
self.help_text = help_text or self.dest
self._hash = self._calc_hash()

Expand Down
10 changes: 5 additions & 5 deletions src/arclet/alconna/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
TypeVar,
Union,
final,
runtime_checkable,
runtime_checkable, Type, Callable,
)
from typing_extensions import NotRequired, TypeAlias

Expand All @@ -26,7 +26,6 @@
TPrefixes = Union[List[Union[str, object]], List[Tuple[object, str]]]
DataUnit = TypeVar("DataUnit", covariant=True)


class _ShortcutRegWrapper(Protocol):
def __call__(self, slot: int | str, content: str | None, context: dict[str, Any]) -> Any: ...

Expand Down Expand Up @@ -145,6 +144,7 @@ class CommandMeta:

TDC = TypeVar("TDC", bound=DataCollection[Any])
T = TypeVar("T")
TAValue: TypeAlias = Union[BasePattern[T, Any, Any], Type[T], T, Callable[..., T], Dict[Any, T], List[T]]


@final
Expand All @@ -167,7 +167,7 @@ class KeyWordVar(BasePattern[T, Any, Literal[MatchMode.KEEP]]):

base: BasePattern

def __init__(self, value: BasePattern[T, Any, Any] | type[T], sep: str = "="):
def __init__(self, value: TAValue[T], sep: str = "="):
"""构建一个具名参数
Args:
Expand All @@ -186,7 +186,7 @@ def __repr__(self):
class _Kw:
__slots__ = ()

def __getitem__(self, item: BasePattern[T, Any, Any] | type[T]):
def __getitem__(self, item: BasePattern[T, Any, Any] | type[T] | Any):
return KeyWordVar(item)

__matmul__ = __getitem__
Expand All @@ -200,7 +200,7 @@ class MultiVar(BasePattern[T, Any, Literal[MatchMode.KEEP]]):
flag: Literal["+", "*"]
length: int

def __init__(self, value: BasePattern[T, Any, Any] | type[T], flag: int | Literal["+", "*"] = "+"):
def __init__(self, value: TAValue[T], flag: int | Literal["+", "*"] = "+"):
"""构建一个可变参数
Args:
Expand Down
8 changes: 4 additions & 4 deletions tests/devtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def analyse_args(
**kwargs
):
meta = CommandMeta(keep_crlf=False, fuzzy_match=False, raise_exception=raise_exception, context_style=context_style)
argv = Argv(meta, dev_space)
argv: Argv[DataCollection] = Argv(meta, dev_space)
try:
argv.enter(kwargs)
argv.build(["test"] + command)
Expand All @@ -69,7 +69,7 @@ def analyse_header(
**kwargs
):
meta = CommandMeta(keep_crlf=False, fuzzy_match=False, raise_exception=raise_exception, context_style=context_style)
argv = Argv(meta, dev_space, separators=(sep,))
argv: Argv[DataCollection] = Argv(meta, dev_space, separators=(sep,))
command_header = Header.generate(command_name, headers, compact=compact)
try:
argv.enter(kwargs)
Expand All @@ -89,7 +89,7 @@ def analyse_option(
**kwargs
):
meta = CommandMeta(keep_crlf=False, fuzzy_match=False, raise_exception=raise_exception, context_style=context_style)
argv = Argv(meta, dev_space)
argv: Argv[DataCollection] = Argv(meta, dev_space)
_analyser = _DummyAnalyser.__new__(_DummyAnalyser)
_analyser.reset()
_analyser.command.separators = (" ",)
Expand All @@ -116,7 +116,7 @@ def analyse_subcommand(
**kwargs
):
meta = CommandMeta(keep_crlf=False, fuzzy_match=False, raise_exception=raise_exception, context_style=context_style)
argv = Argv(meta, dev_space)
argv: Argv[DataCollection] = Argv(meta, dev_space)
_analyser = _DummyAnalyser.__new__(_DummyAnalyser)
_analyser.reset()
_analyser.command.separators = (" ",)
Expand Down

0 comments on commit 72d762d

Please sign in to comment.