diff --git a/CHANGELOG.md b/CHANGELOG.md index 100ad1f1..9975bdc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +## Alconna 1.8.10 + +### 改进 + +- 适配 `NEPattern` 0.7.0 + ## Alconna 1.8.9 ### 修复 diff --git a/pdm.lock b/pdm.lock index c1422aeb..21c923e0 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,21 +5,21 @@ groups = ["default", "dev", "full"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:5a46315d976a9e801e7632cf95d66267c42932d5b258baf08e478ac252773279" +content_hash = "sha256:b65ba5e8efa9c12d2f66e509b9cb0bb0af44839c0930007bc92f2dcf2e44b484" [[package]] name = "arclet-alconna-tools" -version = "0.6.11" +version = "0.7.2" requires_python = ">=3.8" summary = "Builtin Tools for Alconna" groups = ["full"] dependencies = [ - "arclet-alconna>=1.7.39", - "nepattern>=0.5.15", + "arclet-alconna>=1.8.7", + "nepattern<1.0.0,>=0.6.5", ] files = [ - {file = "arclet-alconna-tools-0.6.11.tar.gz", hash = "sha256:079f1ccd84120c65288e50014de2117a0dc7c52e5c2d2d718ad9fd95afb40232"}, - {file = "arclet_alconna_tools-0.6.11-py3-none-any.whl", hash = "sha256:d3bc7d70040fbc1c0b44a9b751089f87c6c487161d7c930dd4018d7ef468d91f"}, + {file = "arclet_alconna_tools-0.7.2-py3-none-any.whl", hash = "sha256:69739aab07c039537cd72b4ab6d37aff896cd794031a8ff8157e5f85e842ed9b"}, + {file = "arclet_alconna_tools-0.7.2.tar.gz", hash = "sha256:98a6aad6284efd8af34b10cd35667bd5885f530327b9ac9ea2944bf6325d0d6f"}, ] [[package]] @@ -35,7 +35,7 @@ files = [ [[package]] name = "black" -version = "24.2.0" +version = "24.4.0" requires_python = ">=3.8" summary = "The uncompromising code formatter." groups = ["dev"] @@ -49,28 +49,28 @@ dependencies = [ "typing-extensions>=4.0.1; python_version < \"3.11\"", ] files = [ - {file = "black-24.2.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6981eae48b3b33399c8757036c7f5d48a535b962a7c2310d19361edeef64ce29"}, - {file = "black-24.2.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d533d5e3259720fdbc1b37444491b024003e012c5173f7d06825a77508085430"}, - {file = "black-24.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61a0391772490ddfb8a693c067df1ef5227257e72b0e4108482b8d41b5aee13f"}, - {file = "black-24.2.0-cp310-cp310-win_amd64.whl", hash = "sha256:992e451b04667116680cb88f63449267c13e1ad134f30087dec8527242e9862a"}, - {file = "black-24.2.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:163baf4ef40e6897a2a9b83890e59141cc8c2a98f2dda5080dc15c00ee1e62cd"}, - {file = "black-24.2.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:e37c99f89929af50ffaf912454b3e3b47fd64109659026b678c091a4cd450fb2"}, - {file = "black-24.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4f9de21bafcba9683853f6c96c2d515e364aee631b178eaa5145fc1c61a3cc92"}, - {file = "black-24.2.0-cp311-cp311-win_amd64.whl", hash = "sha256:9db528bccb9e8e20c08e716b3b09c6bdd64da0dd129b11e160bf082d4642ac23"}, - {file = "black-24.2.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:d84f29eb3ee44859052073b7636533ec995bd0f64e2fb43aeceefc70090e752b"}, - {file = "black-24.2.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1e08fb9a15c914b81dd734ddd7fb10513016e5ce7e6704bdd5e1251ceee51ac9"}, - {file = "black-24.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:810d445ae6069ce64030c78ff6127cd9cd178a9ac3361435708b907d8a04c693"}, - {file = "black-24.2.0-cp312-cp312-win_amd64.whl", hash = "sha256:ba15742a13de85e9b8f3239c8f807723991fbfae24bad92d34a2b12e81904982"}, - {file = "black-24.2.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:7e53a8c630f71db01b28cd9602a1ada68c937cbf2c333e6ed041390d6968faf4"}, - {file = "black-24.2.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:93601c2deb321b4bad8f95df408e3fb3943d85012dddb6121336b8e24a0d1218"}, - {file = "black-24.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a0057f800de6acc4407fe75bb147b0c2b5cbb7c3ed110d3e5999cd01184d53b0"}, - {file = "black-24.2.0-cp38-cp38-win_amd64.whl", hash = "sha256:faf2ee02e6612577ba0181f4347bcbcf591eb122f7841ae5ba233d12c39dcb4d"}, - {file = "black-24.2.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:057c3dc602eaa6fdc451069bd027a1b2635028b575a6c3acfd63193ced20d9c8"}, - {file = "black-24.2.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:08654d0797e65f2423f850fc8e16a0ce50925f9337fb4a4a176a7aa4026e63f8"}, - {file = "black-24.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ca610d29415ee1a30a3f30fab7a8f4144e9d34c89a235d81292a1edb2b55f540"}, - {file = "black-24.2.0-cp39-cp39-win_amd64.whl", hash = "sha256:4dd76e9468d5536abd40ffbc7a247f83b2324f0c050556d9c371c2b9a9a95e31"}, - {file = "black-24.2.0-py3-none-any.whl", hash = "sha256:e8a6ae970537e67830776488bca52000eaa37fa63b9988e8c487458d9cd5ace6"}, - {file = "black-24.2.0.tar.gz", hash = "sha256:bce4f25c27c3435e4dace4815bcb2008b87e167e3bf4ee47ccdc5ce906eb4894"}, + {file = "black-24.4.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6ad001a9ddd9b8dfd1b434d566be39b1cd502802c8d38bbb1ba612afda2ef436"}, + {file = "black-24.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e3a3a092b8b756c643fe45f4624dbd5a389f770a4ac294cf4d0fce6af86addaf"}, + {file = "black-24.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dae79397f367ac8d7adb6c779813328f6d690943f64b32983e896bcccd18cbad"}, + {file = "black-24.4.0-cp310-cp310-win_amd64.whl", hash = "sha256:71d998b73c957444fb7c52096c3843875f4b6b47a54972598741fe9a7f737fcb"}, + {file = "black-24.4.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:8e5537f456a22cf5cfcb2707803431d2feeb82ab3748ade280d6ccd0b40ed2e8"}, + {file = "black-24.4.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:64e60a7edd71fd542a10a9643bf369bfd2644de95ec71e86790b063aa02ff745"}, + {file = "black-24.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5cd5b4f76056cecce3e69b0d4c228326d2595f506797f40b9233424e2524c070"}, + {file = "black-24.4.0-cp311-cp311-win_amd64.whl", hash = "sha256:64578cf99b6b46a6301bc28bdb89f9d6f9b592b1c5837818a177c98525dbe397"}, + {file = "black-24.4.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:f95cece33329dc4aa3b0e1a771c41075812e46cf3d6e3f1dfe3d91ff09826ed2"}, + {file = "black-24.4.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4396ca365a4310beef84d446ca5016f671b10f07abdba3e4e4304218d2c71d33"}, + {file = "black-24.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:44d99dfdf37a2a00a6f7a8dcbd19edf361d056ee51093b2445de7ca09adac965"}, + {file = "black-24.4.0-cp312-cp312-win_amd64.whl", hash = "sha256:21f9407063ec71c5580b8ad975653c66508d6a9f57bd008bb8691d273705adcd"}, + {file = "black-24.4.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:652e55bb722ca026299eb74e53880ee2315b181dfdd44dca98e43448620ddec1"}, + {file = "black-24.4.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7f2966b9b2b3b7104fca9d75b2ee856fe3fdd7ed9e47c753a4bb1a675f2caab8"}, + {file = "black-24.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1bb9ca06e556a09f7f7177bc7cb604e5ed2d2df1e9119e4f7d2f1f7071c32e5d"}, + {file = "black-24.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:d4e71cdebdc8efeb6deaf5f2deb28325f8614d48426bed118ecc2dcaefb9ebf3"}, + {file = "black-24.4.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:6644f97a7ef6f401a150cca551a1ff97e03c25d8519ee0bbc9b0058772882665"}, + {file = "black-24.4.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:75a2d0b4f5eb81f7eebc31f788f9830a6ce10a68c91fbe0fade34fff7a2836e6"}, + {file = "black-24.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eb949f56a63c5e134dfdca12091e98ffb5fd446293ebae123d10fc1abad00b9e"}, + {file = "black-24.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:7852b05d02b5b9a8c893ab95863ef8986e4dda29af80bbbda94d7aee1abf8702"}, + {file = "black-24.4.0-py3-none-any.whl", hash = "sha256:74eb9b5420e26b42c00a3ff470dc0cd144b80a766128b1771d07643165e08d0e"}, + {file = "black-24.4.0.tar.gz", hash = "sha256:f07b69fda20578367eaebbd670ff8fc653ab181e1ff95d84497f9fa20e7d0641"}, ] [[package]] @@ -212,7 +212,7 @@ files = [ [[package]] name = "nepattern" -version = "0.6.4" +version = "0.7.0" requires_python = ">=3.8" summary = "a complex pattern, support typing" groups = ["default", "full"] @@ -221,8 +221,8 @@ dependencies = [ "typing-extensions>=4.5.0", ] files = [ - {file = "nepattern-0.6.4-py3-none-any.whl", hash = "sha256:624e85de9a9a17b99e25d08338f0c99d78235a86a783ddfc66a8a43b0d4dab48"}, - {file = "nepattern-0.6.4.tar.gz", hash = "sha256:30662564090b56f481818c622393f07939434ef713f96772125b9c46ef49d7f3"}, + {file = "nepattern-0.7.0-py3-none-any.whl", hash = "sha256:6cd51145af78a7476486c9f3f3817e8c93a9f4d10e45d8cdcaed62776a9f9a3e"}, + {file = "nepattern-0.7.0.tar.gz", hash = "sha256:75c3b5b93c3ea8aaff585c282d45c1e4db0ebb92e68eecbcaddd3cb33d16dcee"}, ] [[package]] @@ -397,11 +397,11 @@ files = [ [[package]] name = "typing-extensions" -version = "4.9.0" +version = "4.11.0" requires_python = ">=3.8" summary = "Backported and Experimental Type Hints for Python 3.8+" groups = ["default", "dev", "full"] files = [ - {file = "typing_extensions-4.9.0-py3-none-any.whl", hash = "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd"}, - {file = "typing_extensions-4.9.0.tar.gz", hash = "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783"}, + {file = "typing_extensions-4.11.0-py3-none-any.whl", hash = "sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a"}, + {file = "typing_extensions-4.11.0.tar.gz", hash = "sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0"}, ] diff --git a/pyproject.toml b/pyproject.toml index 71a5508a..ea127bcb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] diff --git a/src/arclet/alconna/__init__.py b/src/arclet/alconna/__init__.py index bee38e61..2e4d14f4 100644 --- a/src/arclet/alconna/__init__.py +++ b/src/arclet/alconna/__init__.py @@ -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 diff --git a/src/arclet/alconna/_internal/_handlers.py b/src/arclet/alconna/_internal/_handlers.py index 4f0d686d..1cdc06a1 100644 --- a/src/arclet/alconna/_internal/_handlers.py +++ b/src/arclet/alconna/_internal/_handlers.py @@ -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) diff --git a/src/arclet/alconna/_internal/_header.py b/src/arclet/alconna/_internal/_header.py index b4237818..f2bab50b 100644 --- a/src/arclet/alconna/_internal/_header.py +++ b/src/arclet/alconna/_internal/_header.py @@ -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 diff --git a/src/arclet/alconna/args.py b/src/arclet/alconna/args.py index 3c5a83e5..ed6e9aec 100644 --- a/src/arclet/alconna/args.py +++ b/src/arclet/alconna/args.py @@ -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): @@ -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) """参数单元的字段""" diff --git a/src/arclet/alconna/typing.py b/src/arclet/alconna/typing.py index f9f9da0d..1878fc33 100644 --- a/src/arclet/alconna/typing.py +++ b/src/arclet/alconna/typing.py @@ -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="*") @@ -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: @@ -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: diff --git a/tests/args_test.py b/tests/args_test.py index d3b1eca2..fdb68659 100644 --- a/tests/args_test.py +++ b/tests/args_test.py @@ -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 @@ -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} diff --git a/tests/core_test.py b/tests/core_test.py index 1e08a0f9..2f910774 100644 --- a/tests/core_test.py +++ b/tests/core_test.py @@ -58,7 +58,7 @@ def test_alconna_multi_match(): 可用的子命令有: * 测试用例 - test + test 该子命令内可用的选项有: * 输入用户名 -u @@ -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 丢失"