Skip to content

Commit

Permalink
⬆️ version 1.8.10
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Apr 21, 2024
1 parent dea9dfb commit 70f246d
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 60 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.10

### 改进

- 适配 `NEPattern` 0.7.0

## Alconna 1.8.9

### 修复
Expand Down
70 changes: 35 additions & 35 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
]
dependencies = [
"typing-extensions>=4.5.0",
"nepattern<1.0.0,>=0.6.4",
"nepattern<1.0.0,>=0.7.0",
"tarina>=0.4.4",
]
dynamic = ["version"]
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.9"
__version__ = "1.8.10"

# backward compatibility
AnyOne = ANY
2 changes: 1 addition & 1 deletion src/arclet/alconna/_internal/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _context(argv: Argv, target: Arg[Any], _arg: str):
)


def _validate(argv: Argv, target: Arg[Any], value: BasePattern[Any, Any], result: dict[str, Any], arg: Any, _str: bool):
def _validate(argv: Argv, target: Arg[Any], value: BasePattern[Any, Any, Any], result: dict[str, Any], arg: Any, _str: bool):
_arg = arg
if _str and argv.context_style:
_arg = _context(argv, target, _arg)
Expand Down
10 changes: 1 addition & 9 deletions src/arclet/alconna/_internal/_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
def prefixed(pat: BasePattern):
if pat.mode not in (MatchMode.REGEX_MATCH, MatchMode.REGEX_CONVERT):
return pat
new_pat = BasePattern(
pattern=pat.pattern,
mode=pat.mode,
origin=pat.origin,
converter=pat.converter,
alias=pat.alias,
previous=pat.previous,
validators=pat.validators,
)
new_pat = pat.copy()
new_pat.regex_pattern = re.compile(f"^{new_pat.pattern}")
return new_pat

Expand Down
4 changes: 2 additions & 2 deletions src/arclet/alconna/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def safe_dcls_kw(**kwargs):


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


class ArgFlag(str, Enum):
Expand Down Expand Up @@ -79,7 +79,7 @@ class Arg(Generic[_T]):

name: str = dc.field(compare=True, hash=True)
"""参数单元的名称"""
value: BasePattern[_T, Any] = dc.field(compare=False, hash=True)
value: BasePattern[_T, Any, Any] = dc.field(compare=False, hash=True)
"""参数单元的值"""
field: Field[_T] = dc.field(compare=False, hash=False)
"""参数单元的字段"""
Expand Down
14 changes: 7 additions & 7 deletions src/arclet/alconna/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CommandMeta:


@final
class _AllParamPattern(BasePattern[Any, Any]):
class _AllParamPattern(BasePattern[Any, Any, Literal[MatchMode.KEEP]]):
def __init__(self):
super().__init__(mode=MatchMode.KEEP, origin=Any, alias="*")

Expand All @@ -139,12 +139,12 @@ def __calc_eq__(self, other): # pragma: no cover
AllParam = _AllParamPattern()


class KeyWordVar(BasePattern[T, Any]):
class KeyWordVar(BasePattern[T, Any, Literal[MatchMode.KEEP]]):
"""对具名参数的包装"""

base: BasePattern

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

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

__matmul__ = __getitem__
__rmatmul__ = __getitem__


class MultiVar(BasePattern[T, Any]):
class MultiVar(BasePattern[T, Any, Literal[MatchMode.KEEP]]):
"""对可变参数的包装"""

base: BasePattern[T, Any]
base: BasePattern[T, Any, Any]
flag: Literal["+", "*"]
length: int

def __init__(self, value: BasePattern[T, Any] | type[T], flag: int | Literal["+", "*"] = "+"):
def __init__(self, value: BasePattern[T, Any, Any] | type[T], flag: int | Literal["+", "*"] = "+"):
"""构建一个可变参数
Args:
Expand Down
4 changes: 2 additions & 2 deletions tests/args_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Union

from nepattern import BasePattern, Bind, MatchMode
from nepattern import BasePattern, MatchMode, INTEGER, combine

from arclet.alconna import ArgFlag, Args, KeyWordVar, Kw, Nargs
from devtool import analyse_args
Expand Down Expand Up @@ -205,7 +205,7 @@ def test(time: Union[int, str]) -> datetime:
def test_annotated():
from typing_extensions import Annotated

arg18 = Args["foo", Annotated[int, lambda x: x > 0]]["bar", Bind[int, lambda x: x < 0]]
arg18 = Args["foo", Annotated[int, lambda x: x > 0]]["bar", combine(INTEGER, validators=[lambda x: x < 0])]
assert analyse_args(arg18, ["123 -123"]) == {"foo": 123, "bar": -123}
assert analyse_args(arg18, ["0 0"], raise_exception=False) != {"foo": 0, "bar": 0}

Expand Down
4 changes: 2 additions & 2 deletions tests/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_alconna_multi_match():
可用的子命令有:
* 测试用例
test <test: Test>
test <test: 'Test'>
该子命令内可用的选项有:
* 输入用户名
-u <username: str>
Expand Down Expand Up @@ -913,7 +913,7 @@ def test_tips():
assert core27.parse("core27 1 1").matched
assert str(core27.parse("core27 3 1").error_info) == "参数arg必须是1或2哦,不能是3"
assert str(core27.parse("core27 1").error_info) == "缺少了arg参数哦"
assert str(core27.parse("core27 1 3").error_info) in ("参数 '3' 不正确, 其应该符合 '1|2'", "参数 '3' 不正确, 其应该符合 '2|1'")
assert str(core27.parse("core27 1 3").error_info) in ("参数 '3' 不正确, 其应该符合 \"'1'|'2'\"", "参数 '3' 不正确, 其应该符合 \"'2'|'1'\"")
assert str(core27.parse("core27").error_info) == "参数 arg1 丢失"


Expand Down

0 comments on commit 70f246d

Please sign in to comment.