Voice et bot modif
This commit is contained in:
parent
189d56026b
commit
7333a22bcd
10774 changed files with 634644 additions and 933308 deletions
|
|
@ -50,7 +50,7 @@ V = t.TypeVar("V")
|
|||
|
||||
def _unpack_args(
|
||||
args: cabc.Sequence[str], nargs_spec: cabc.Sequence[int]
|
||||
) -> tuple[cabc.Sequence[str | cabc.Sequence[str | None] | None], list[str]]:
|
||||
) -> tuple[cabc.Sequence[str | cabc.Sequence[str | T_UNSET] | T_UNSET], list[str]]:
|
||||
"""Given an iterable of arguments and an iterable of nargs specifications,
|
||||
it returns a tuple with all the unpacked arguments at the first index
|
||||
and all remaining arguments as the second.
|
||||
|
|
@ -65,7 +65,7 @@ def _unpack_args(
|
|||
rv: list[str | tuple[str | T_UNSET, ...] | T_UNSET] = []
|
||||
spos: int | None = None
|
||||
|
||||
def _fetch(c: deque[V]) -> V | T_UNSET:
|
||||
def _fetch(c: deque[str]) -> str | T_UNSET:
|
||||
try:
|
||||
if spos is None:
|
||||
return c.popleft()
|
||||
|
|
@ -75,15 +75,15 @@ def _unpack_args(
|
|||
return UNSET
|
||||
|
||||
while nargs_spec:
|
||||
nargs = _fetch(nargs_spec)
|
||||
|
||||
if nargs is None:
|
||||
continue
|
||||
if spos is None:
|
||||
nargs = nargs_spec.popleft()
|
||||
else:
|
||||
nargs = nargs_spec.pop()
|
||||
|
||||
if nargs == 1:
|
||||
rv.append(_fetch(args)) # type: ignore[arg-type]
|
||||
rv.append(_fetch(args))
|
||||
elif nargs > 1:
|
||||
x = [_fetch(args) for _ in range(nargs)]
|
||||
x: list[str | T_UNSET] = [_fetch(args) for _ in range(nargs)]
|
||||
|
||||
# If we're reversed, we're pulling in the arguments in reverse,
|
||||
# so we need to turn them around.
|
||||
|
|
@ -141,7 +141,11 @@ class _Option:
|
|||
for opt in opts:
|
||||
prefix, value = _split_opt(opt)
|
||||
if not prefix:
|
||||
raise ValueError(f"Invalid start character for option ({opt})")
|
||||
raise ValueError(
|
||||
_("Invalid start character for option ({option})").format(
|
||||
option=opt
|
||||
)
|
||||
)
|
||||
self.prefixes.add(prefix[0])
|
||||
if len(prefix) == 1 and len(value) == 1:
|
||||
self._short_opts.append(opt)
|
||||
|
|
@ -186,12 +190,12 @@ class _Argument:
|
|||
|
||||
def process(
|
||||
self,
|
||||
value: str | cabc.Sequence[str | None] | None | T_UNSET,
|
||||
value: str | cabc.Sequence[str | T_UNSET] | T_UNSET,
|
||||
state: _ParsingState,
|
||||
) -> None:
|
||||
if self.nargs > 1:
|
||||
assert isinstance(value, cabc.Sequence)
|
||||
holes = sum(1 for x in value if x is UNSET)
|
||||
holes = sum(x is UNSET for x in value)
|
||||
if holes == len(value):
|
||||
value = UNSET
|
||||
elif holes != 0:
|
||||
|
|
@ -360,10 +364,7 @@ class _OptionParser:
|
|||
self, opt: str, explicit_value: str | None, state: _ParsingState
|
||||
) -> None:
|
||||
if opt not in self._long_opt:
|
||||
from difflib import get_close_matches
|
||||
|
||||
possibilities = get_close_matches(opt, self._long_opt)
|
||||
raise NoSuchOption(opt, possibilities=possibilities, ctx=self.ctx)
|
||||
raise NoSuchOption(opt, possibilities=self._long_opt, ctx=self.ctx)
|
||||
|
||||
option = self._long_opt[opt]
|
||||
if option.takes_value:
|
||||
|
|
@ -421,17 +422,17 @@ class _OptionParser:
|
|||
|
||||
# If we got any unknown options we recombine the string of the
|
||||
# remaining options and re-attach the prefix, then report that
|
||||
# to the state as new larg. This way there is basic combinatorics
|
||||
# to the state as new large. This way there is basic combinatorics
|
||||
# that can be achieved while still ignoring unknown arguments.
|
||||
if self.ignore_unknown_options and unknown_options:
|
||||
state.largs.append(f"{prefix}{''.join(unknown_options)}")
|
||||
|
||||
def _get_value_from_state(
|
||||
self, option_name: str, option: _Option, state: _ParsingState
|
||||
) -> str | cabc.Sequence[str] | T_FLAG_NEEDS_VALUE:
|
||||
) -> str | cabc.Sequence[str] | T_UNSET | T_FLAG_NEEDS_VALUE:
|
||||
nargs = option.nargs
|
||||
|
||||
value: str | cabc.Sequence[str] | T_FLAG_NEEDS_VALUE
|
||||
value: str | cabc.Sequence[str] | T_UNSET | T_FLAG_NEEDS_VALUE
|
||||
|
||||
if len(state.rargs) < nargs:
|
||||
if option.obj._flag_needs_value:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue