Skip to content

Commit

Permalink
⬆️ version 1.7.21
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Sep 8, 2023
1 parent b491cab commit c7113f1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# 更新日志

## Alconna 1.7.21

### 改进:
- 升级 `NEPattern` 至 0.5.14

## Alconna 1.7.20

### 改进:
Expand Down
8 changes: 4 additions & 4 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<0.6.0, >=0.5.13",
"nepattern<0.6.0, >=0.5.14",
"tarina>=0.3.3",
]
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 @@ -49,7 +49,7 @@
from .typing import UnpackVar as UnpackVar
from .typing import Up as Up

__version__ = "1.7.20"
__version__ = "1.7.21"

# backward compatibility
Arpamar = Arparma
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 @@ -9,7 +9,7 @@
from functools import partial
from typing import Any, Callable, Generic, Iterable, Sequence, TypeVar, Union, Type, List

from nepattern import AllParam, AnyOne, BasePattern, RawStr, UnionPattern, all_patterns, type_parser
from nepattern import AllParam, AnyOne, BasePattern, MatchMode, RawStr, UnionPattern, all_patterns, type_parser
from tarina import Empty, get_signature, lang
from typing_extensions import Self, TypeAlias

Expand Down Expand Up @@ -219,7 +219,7 @@ def from_callable(cls, target: Callable, kw_sep: str = "=") -> tuple[Args, bool]
de = NULL.get(de, de)
if param.kind == param.KEYWORD_ONLY:
if anno == bool:
anno = KWBool(f"(?:-*no)?-*{name}", 3, bool, lambda _, x: not x.lstrip("-").startswith('no'))
anno = KWBool(f"(?:-*no)?-*{name}", MatchMode.REGEX_CONVERT, bool, lambda _, x: not x[0].lstrip("-").startswith('no'))
anno = KeyWordVar(anno, sep=kw_sep)
if param.kind == param.VAR_POSITIONAL:
anno = MultiVar(anno, "*")
Expand Down
6 changes: 3 additions & 3 deletions src/arclet/alconna/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, value: BasePattern | Any, sep: str = '='):
self.base = value if isinstance(value, BasePattern) else type_parser(value)
self.sep = sep
assert isinstance(self.base, BasePattern)
super().__init__(r"(.+?)", MatchMode.KEEP, self.base.origin, alias=f"@{sep}{self.base}")
super().__init__(model=MatchMode.KEEP, origin=self.base.origin, alias=f"@{sep}{self.base}")

def __repr__(self):
return self.alias
Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(self, value: BasePattern | Any, flag: int | Literal["+", "*"] = "+"
self.flag = "+"
self.length = 1
origin = Dict[str, self.base.origin] if isinstance(self.base, KeyWordVar) else Tuple[self.base.origin, ...]
super().__init__(r"(.+?)", MatchMode.KEEP, origin, alias=alias)
super().__init__(model=MatchMode.KEEP, origin=origin, alias=alias)

def __repr__(self):
return self.alias
Expand Down Expand Up @@ -129,7 +129,7 @@ def __init__(self, dcls: Any):
raise TypeError(dcls)
self.fields = fields(dcls) # can override if other use Pydantic?
alias = f"{dcls.__name__}(" + ", ".join(f"{f.name}: {f.type.__name__}" for f in self.fields)
super().__init__(r"", MatchMode.KEEP, dcls, alias=alias) # type: ignore
super().__init__(model=MatchMode.KEEP, origin=dcls, alias=alias) # type: ignore


class _Up:
Expand Down
2 changes: 1 addition & 1 deletion tests/args_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_kwonly():

def test_pattern():
test_type = BasePattern(
"(.+?).py", MatchMode.REGEX_CONVERT, list, lambda _, x: x.split("/"), "test"
"(.+?).py", MatchMode.REGEX_CONVERT, list, lambda _, x: x[1].split("/"), "test"
)
arg15 = Args().add("bar", value=test_type)
assert analyse_args(arg15, ["abc.py"]) == {"bar": ["abc"]}
Expand Down
7 changes: 4 additions & 3 deletions tests/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def test_alconna_synthesise():
from typing import List
from nepattern import BasePattern, MatchMode

cnt = BasePattern(r".*(\d+)张.*", MatchMode.REGEX_CONVERT, int, lambda _, x: int(x))
cnt = BasePattern(r".*(\d+)张.*", MatchMode.REGEX_CONVERT, int, lambda _, x: int(x[1]))
alc10 = Alconna(
Arg("min", cnt, seps="到"),
Arg("max;?", cnt),
Expand Down Expand Up @@ -599,6 +599,7 @@ class A:

def test_action():
from arclet.alconna import append, append_value, count, store_true
from typing import List

alc24 = Alconna(
"core24", Option("--yes|-y", action=store_true), Args["module", AllParam]
Expand Down Expand Up @@ -629,8 +630,8 @@ def test_action():
"foo bar --q foo bar --qq"
)
assert res.query[int]("i.foo") == 5
assert res.query["list[int]"]("a.value") == [1, 1]
assert res.query["list[str]"]("flag.flag") == ["abc", "def", "xyz"]
assert res.query[List[int]]("a.value") == [1, 1]
assert res.query[List[str]]("flag.flag") == ["abc", "def", "xyz"]
assert res.query[int]("v.value") == 3
assert res.query[int]("xyz.value") == 4
assert res.query[int]("foo_bar_q.value") == 3
Expand Down

0 comments on commit c7113f1

Please sign in to comment.