Skip to content

Commit

Permalink
:fix: type
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Feb 24, 2024
1 parent 1fb4420 commit 3dc2c87
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/
.pdm-python
.pdm-python
.idea/
3 changes: 0 additions & 3 deletions example/pip.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from arclet.alconna import Alconna, Option, count, Subcommand, Args, MultiVar, store_true
from nepattern import URL, create_local_patterns
from nepattern.main import StrPath
from pathlib import Path
from typing import Tuple

create_local_patterns("example/pip", {Path: StrPath})


pip = Alconna(
"/pip",
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/_internal/_argv.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def reset(self):
self.bak_data = []
self.raw_data = []
self.token = 0
self.origin = "None"
self.origin = "None" # type: ignore
self._sep = None
self.context = None

Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/_internal/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
pat = re.compile("(?:-*no)?-*(?P<name>.+)")


def _validate(argv: Argv, target: Arg[Any], value: BasePattern[Any], result: dict[str, Any], arg: Any, _str: bool):
def _validate(argv: Argv, target: Arg[Any], value: BasePattern[Any, Any], result: dict[str, Any], arg: Any, _str: bool):
if (value is STRING and _str) or value is ANY:
result[target.name] = arg
return
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __init__(
_value = parser(value or RawStr(name))
default = field if isinstance(field, Field) else Field(field)
if isinstance(_value, UnionPattern) and _value.optional:
default.default = None if default.default is Empty else default.default
default.default = None if default.default is Empty else default.default # type: ignore
if _value == NONE:
raise InvalidArgs(lang.require("args", "value_error").format(target=name))
self.value = _value
Expand Down
4 changes: 2 additions & 2 deletions src/arclet/alconna/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Option(CommandNode):
相比命令节点, 命令选项可以设置别名, 优先级, 允许名称与后随参数之间无分隔符
"""

default: OptionResult | type[Empty]
default: OptionResult
"""命令选项默认值"""
aliases: frozenset[str]
"""命令选项别名"""
Expand Down Expand Up @@ -257,7 +257,7 @@ class Subcommand(CommandNode):
与命令节点不同, 子命令可以包含多个命令选项与相对于自己的子命令
"""

default: SubcommandResult | type[Empty]
default: SubcommandResult
"""子命令默认值"""
options: list[Option | Subcommand]
"""子命令包含的选项与子命令"""
Expand Down
3 changes: 1 addition & 2 deletions src/arclet/alconna/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ def __init__(self, value: BasePattern[T, Any] | type[T], flag: int | Literal["+"
alias = str(self.base)
self.flag = "+"
self.length = 1
origin = Dict[str, self.base.origin] if isinstance(self.base, KeyWordVar) else Tuple[self.base.origin, ...]
super().__init__(mode=MatchMode.KEEP, origin=origin, alias=alias)
super().__init__(mode=MatchMode.KEEP, origin=self.base.origin, alias=alias)

def __repr__(self):
return self.alias
Expand Down

0 comments on commit 3dc2c87

Please sign in to comment.