From af64958a2847c4c0a696af79afcc7d4d7b6136f6 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Wed, 11 Nov 2026 17:01:38 -0800 Subject: [PATCH 01/18] Rebase changes for parser on main. --- src/click/core.py | 448 +++++++++++++++++++++++++--------- src/click/shell_completion.py | 10 +- tests/test_arguments.py | 11 + tests/test_basic.py | 2 +- tests/test_options.py | 28 ++- tests/test_parser.py | 17 +- tests/test_termui.py | 2 +- 7 files changed, 388 insertions(+), 130 deletions(-) diff --git a/src/click/core.py b/src/click/core.py index b4317257c..12e9d3b0c 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -11,6 +11,7 @@ from abc import abstractmethod from collections import abc from collections import Counter +from collections import defaultdict from contextlib import AbstractContextManager from contextlib import contextmanager from contextlib import ExitStack @@ -25,18 +26,20 @@ from ._utils import FLAG_NEEDS_VALUE from ._utils import UNSET from .exceptions import Abort +from .exceptions import BadArgumentUsage +from .exceptions import BadOptionUsage from .exceptions import BadParameter from .exceptions import ClickException from .exceptions import Exit from .exceptions import MissingParameter from .exceptions import NoArgsIsHelpError from .exceptions import NoSuchCommand +from .exceptions import NoSuchOption from .exceptions import UsageError from .formatting import HelpFormatter from .formatting import join_options from .globals import pop_context from .globals import push_context -from .parser import _OptionParser from .parser import _split_opt from .termui import confirm from .termui import prompt @@ -46,7 +49,6 @@ from .utils import _make_default_short_help from .utils import _PacifyFlushWrapper from .utils import echo -from .utils import make_str if t.TYPE_CHECKING: from typing_extensions import Self @@ -344,7 +346,6 @@ class Context: info_name: str | None params: dict[str, t.Any] args: list[str] - _protected_args: list[str] _opt_prefixes: set[str] obj: t.Any _meta: dict[str, t.Any] @@ -397,11 +398,6 @@ def __init__( self.params = {} #: the leftover arguments. self.args = [] - #: protected arguments. These are arguments that are prepended - #: to `args` when certain parsing scenarios are encountered but - #: must be never propagated to another arguments. This is used - #: to implement nested parsing. - self._protected_args = [] #: the collected prefixes of the command's options. self._opt_prefixes = set(parent._opt_prefixes) if parent else set() @@ -552,7 +548,7 @@ def protected_args(self) -> list[str]: DeprecationWarning, stacklevel=2, ) - return self._protected_args + return [] def to_info_dict(self) -> dict[str, t.Any]: """Gather information that could be useful for a tool generating @@ -1249,13 +1245,6 @@ def get_help_option(self, ctx: Context) -> Option | None: return self._help_option - def make_parser(self, ctx: Context) -> _OptionParser: - """Creates the underlying option parser for this command.""" - parser = _OptionParser(ctx) - for param in self.get_params(ctx): - param.add_to_parser(parser, ctx) - return parser - def get_help(self, ctx: Context) -> str: """Formats the help into a string and returns it. @@ -1393,11 +1382,296 @@ def parse_args(self, ctx: Context, args: list[str]) -> list[str]: if not args and self.no_args_is_help and not ctx.resilient_parsing: raise NoArgsIsHelpError(ctx) - parser = self.make_parser(ctx) - opts, args, param_order = parser.parse_args(args=args) + token_normalize_func = ctx.token_normalize_func + + def normalize(name: str) -> str: + if token_normalize_func is None: + return name + + prefix, name = _split_opt(name) + return f"{prefix}{token_normalize_func(name)}" + + params = self.get_params(ctx) + # Map each short and long option flag to their option objects, and collect the + # order of positional arguments. The one and two character prefixes used by + # options are collected to check if a token looks like an option. + opt_prefixes: set[str] = {"-", "--"} + short_opts: dict[str, Option] = {} + long_opts: dict[str, Option] = {} + # Normalized secondary names, for easier comparison during parsing. + secondary_opts: set[str] = set() + arg_params: list[Argument] = [] + + for param in params: + if isinstance(param, Option): + names = list(param.opts) + + if param.is_bool_flag and param.secondary_opts: + names.extend(param.secondary_opts) + secondary_opts.update(normalize(n) for n in param.secondary_opts) + + for name in names: + name = normalize(name) + prefix, value = _split_opt(name) + opt_prefixes.add(prefix[0]) + + if len(prefix) == 1 and len(value) == 1: + # -a is a short opt + short_opts[name] = param + else: + # --a is a long opt, -ab is a long opt with a short prefix + opt_prefixes.add(prefix) + long_opts[name] = param + + elif isinstance(param, Argument): + arg_params.append(param) + + def looks_like_opt(token: str) -> bool: + return len(token) > 1 and token[:1] in opt_prefixes + + def flag_value(opt: Option, name: str) -> t.Any: + if opt.count: + # Each occurrence records the running count, the last one is used. + return len(values[opt.name]) + 1 + + if opt.is_bool_flag and opt.secondary_opts: + return name not in secondary_opts + + return opt.flag_activation_value + + # Map parameter names to collected values. + values: defaultdict[str, list[t.Any]] = defaultdict(list) + # Track what order parameters were seen. + param_order: list[Parameter] = [] + # After mapping arguments to values, any extra values will still be here. + rest: list[str] = [] + # Track what the parser should do with the current token. + lf_any = 0 + lf_value_or_opt = 1 + lf_value = 2 + looking_for = lf_any + # Tracks the current option that needs a value. + looking_opt: Option | None = None + looking_opt_name: str | None = None + # Treat tokens as a stack, with the first token at the top. + tokens = list(reversed(args)) + + try: + while tokens: + token = tokens.pop() + + if looking_for == lf_any: + if token == "--": + # All tokens after -- are considered arguments. + rest.extend(reversed(tokens)) + tokens.clear() + elif looks_like_opt(token): + original_name, long_sep, value = token.partition("=") + name = normalize(original_name) + + if name in long_opts: + # any prefix, matching long opt + opt = long_opts[name] + param_order.append(opt) + takes_value = not (opt.is_flag or opt.count) + + if long_sep: + # key=value, only valid if the option takes a value + if not takes_value: + message = _( + "Option {name!r} does not take a value." + ).format(name=original_name) + raise BadOptionUsage( + original_name, message, ctx=ctx + ) + + tokens.append(value) + looking_opt = opt + looking_opt_name = original_name + looking_for = lf_value + elif not takes_value: + # no attached value, and no value needed + values[opt.name].append(flag_value(opt, name)) + else: + # no attached value, and a value may be needed + looking_opt = opt + looking_opt_name = original_name + + if opt._flag_needs_value: + looking_for = lf_value_or_opt + else: + looking_for = lf_value + elif token[:2] in opt_prefixes: + # long prefix, no matching long opt + if not ctx.ignore_unknown_options: + raise NoSuchOption( + original_name, possibilities=long_opts, ctx=ctx + ) + + rest.append(token) + else: + # short prefix, try short opts + prefix = token[0] + chars = token[1:] + unmatched = [] + + for i, c in enumerate(chars, 1): + original_name = f"{prefix}{c}" + name = normalize(original_name) + + if name not in short_opts: + if not ctx.ignore_unknown_options: + raise NoSuchOption(name, ctx=ctx) + + unmatched.append(c) + continue + + opt = short_opts[name] + param_order.append(opt) + + if opt.is_flag or opt.count: + # Record the flag, then continue trying short opts. + values[opt.name].append(flag_value(opt, name)) + continue + + # Not a flag, stop trying short options and begin + # looking for values. + looking_opt = opt + looking_opt_name = original_name + value = chars[i:] + + if value: + # Use any remaining chars as a value. + tokens.append(value) + looking_for = lf_value + elif opt._flag_needs_value: + looking_for = lf_value_or_opt + else: + looking_for = lf_value + + break + + if unmatched: + # If unknown options are allowed, add any unused chars + # back as a single name with the same prefix. + rest.append(f"{prefix}{''.join(unmatched)}") + else: + # an argument + rest.append(token) + + if not ctx.allow_interspersed_args: + # If interspersed isn't allowed, all remaining + # tokens are considered arguments. + rest.extend(reversed(tokens)) + tokens.clear() + elif looking_for == lf_value_or_opt: + # The current opt optionally takes a value. Look at the + # token then put it back. + assert looking_opt is not None + tokens.append(token) + + if (looking_opt.nargs == 1 and looks_like_opt(token)) or len( + tokens + ) < looking_opt.nargs: + # Next token is an opt, or there aren't enough tokens left. + # Mark the current opt as needing a value, handled during + # processing. + values[looking_opt.name].append(FLAG_NEEDS_VALUE) + looking_opt = looking_opt_name = None + looking_for = lf_any + else: + # Next token will be used as a value. + looking_for = lf_value + elif looking_for == lf_value: + # The current opt requires at least one value. + assert looking_opt is not None and looking_opt_name is not None + + if looking_opt.nargs == 1: + # Exactly one value required + values[looking_opt.name].append(token) + else: + # More than one value required + need_n = looking_opt.nargs - 1 + + if len(tokens) < need_n: + message = ngettext( + "Option {name!r} requires {nargs} values" + " but 1 was given.", + "Option {name!r} requires {nargs} values" + " but {len} were given.", + len(tokens) + 1, + ).format( + name=looking_opt_name, + nargs=looking_opt.nargs, + len=len(tokens) + 1, + ) + raise BadOptionUsage(looking_opt_name, message, ctx=ctx) + + values[looking_opt.name].append( + (token, *reversed(tokens[-need_n:])) + ) + del tokens[-need_n:] + + looking_opt = looking_opt_name = None + looking_for = lf_any + + if looking_for == lf_value_or_opt: + # No more tokens, mark the current opt to get a value later. + assert looking_opt is not None + values[looking_opt.name].append(FLAG_NEEDS_VALUE) + elif looking_for == lf_value: + # No more tokens, but the current opt still required a value. + assert looking_opt is not None and looking_opt_name is not None + message = ngettext( + "Option {name!r} requires a value.", + "Option {name!r} requires {nargs} values.", + looking_opt.nargs, + ).format(name=looking_opt_name, nargs=looking_opt.nargs) + raise BadOptionUsage(looking_opt_name, message, ctx=ctx) + + # Treat args as a stack, with the first at the top. + arg_params.reverse() + + while arg_params: + arg = arg_params.pop() + param_order.append(arg) + + # Missing values aren't recorded, so the value can come from an env + # var or default, or be reported as missing during processing. + if arg.nargs == -1: + need_n = sum(p.nargs for p in arg_params if p.nargs > 0) + + if need_n: + buffer = rest[:-need_n] + rest = rest[-need_n:] + else: + buffer = rest + rest = [] + + if buffer: + values[arg.name].append(tuple(buffer)) + elif arg.nargs == 1: + if rest: + values[arg.name].append(rest.pop(0)) + elif len(rest) >= arg.nargs: + values[arg.name].append(tuple(rest[: arg.nargs])) + rest = rest[arg.nargs :] + elif rest: + message = ngettext( + "Argument {name!r} requires {nargs} values but 1 was given.", + "Argument {name!r} requires {nargs} values" + " but {len} were given.", + len(rest), + ).format(name=arg.make_metavar(ctx), nargs=arg.nargs, len=len(rest)) + raise BadArgumentUsage(message, ctx=ctx) + except UsageError: + if not ctx.resilient_parsing: + raise + + args = rest - for param in iter_params_for_processing(param_order, self.get_params(ctx)): - _, args = param.handle_parse_result(ctx, opts, args) + for param in iter_params_for_processing(param_order, params): + args = param.handle_parse_result(ctx, values, args)[1] # We now have all parameters' values into `ctx.params`, but the data may contain # the `UNSET` sentinel. @@ -1410,16 +1684,15 @@ def parse_args(self, ctx: Context, args: list[str]) -> list[str]: ctx.params[name] = None if args and not ctx.allow_extra_args and not ctx.resilient_parsing: - ctx.fail( - ngettext( - "Got unexpected extra argument ({args})", - "Got unexpected extra arguments ({args})", - len(args), - ).format(args=" ".join(map(str, args))) - ) + message = ngettext( + "Got unexpected extra argument ({args})", + "Got unexpected extra arguments ({args})", + len(args), + ).format(args=" ".join(args)) + raise BadArgumentUsage(message, ctx=ctx) ctx.args = args - ctx._opt_prefixes.update(parser._opt_prefixes) + ctx._opt_prefixes.update(opt_prefixes) return args def invoke(self, ctx: Context) -> t.Any: @@ -1480,7 +1753,7 @@ def shell_complete(self, ctx: Context, incomplete: str) -> list[CompletionItem]: results.extend( CompletionItem(name, help=command.get_short_help_str()) for name, command in _complete_visible_commands(ctx, incomplete) - if name not in ctx._protected_args + if name not in ctx.args ) return results @@ -2028,27 +2301,13 @@ def format_commands(self, ctx: Context, formatter: HelpFormatter) -> None: with formatter.section(_("Commands")): formatter.write_dl(rows) - def parse_args(self, ctx: Context, args: list[str]) -> list[str]: - if not args and self.no_args_is_help and not ctx.resilient_parsing: - raise NoArgsIsHelpError(ctx) - - rest = super().parse_args(ctx, args) - - if self.chain: - ctx._protected_args = rest - ctx.args = [] - elif rest: - ctx._protected_args, ctx.args = rest[:1], rest[1:] - - return ctx.args - def invoke(self, ctx: Context) -> t.Any: def _process_result(value: t.Any) -> t.Any: if self._result_callback is not None: value = ctx.invoke(self._result_callback, value, **ctx.params) return value - if not ctx._protected_args: + if not ctx.args: if self.invoke_without_command: # No subcommand was invoked, so the result callback is # invoked with the group return value for regular @@ -2058,10 +2317,8 @@ def _process_result(value: t.Any) -> t.Any: return _process_result([] if self.chain else rv) ctx.fail(_("Missing command.")) - # Fetch args back out - args = [*ctx._protected_args, *ctx.args] + args = ctx.args ctx.args = [] - ctx._protected_args = [] # If we're not in chain mode, we only allow the invocation of a # single command but we also inform the current context about the @@ -2113,28 +2370,26 @@ def _process_result(value: t.Any) -> t.Any: def resolve_command( self, ctx: Context, args: list[str] ) -> tuple[str | None, Command | None, list[str]]: - cmd_name = make_str(args[0]) + name = original_name = args[0] + cmd = self.get_command(ctx, name) - # Get the command - cmd = self.get_command(ctx, cmd_name) - - # If we can't find the command but there is a normalization - # function available, we try with that one. + # If there's no exact match, try matching the normalized name. if cmd is None and ctx.token_normalize_func is not None: - cmd_name = ctx.token_normalize_func(cmd_name) - cmd = self.get_command(ctx, cmd_name) - - # If we don't find the command we want to show an error message - # to the user that it was not provided. However, there is - # something else we should do: if the first argument looks like - # an option we want to kick off parsing again for arguments to - # resolve things like --help which now should go to the main - # place. - if cmd is None and not ctx.resilient_parsing: - if _split_opt(cmd_name)[0]: + name = ctx.token_normalize_func(name) + cmd = self.get_command(ctx, name) + + if cmd is None: + if ctx.resilient_parsing: + return None, None, args[1:] + + # Parsing stops at the first argument, so options like --help may be + # left over. Parse them again so they can be handled. + if _split_opt(original_name)[0]: self.parse_args(ctx, args) - raise NoSuchCommand(cmd_name, possibilities=self.commands, ctx=ctx) - return cmd_name if cmd else None, cmd, args[1:] + + raise NoSuchCommand(original_name, possibilities=self.commands, ctx=ctx) + + return name, cmd, args[1:] def shell_complete(self, ctx: Context, incomplete: str) -> list[CompletionItem]: """Return a list of completions for the incomplete value. Looks @@ -2664,11 +2919,8 @@ def get_default( return value - @abstractmethod - def add_to_parser(self, parser: _OptionParser, ctx: Context) -> None: ... - def consume_value( - self, ctx: Context, opts: cabc.Mapping[str, t.Any] + self, ctx: Context, opts: cabc.Mapping[str, list[t.Any]] ) -> tuple[t.Any, ParameterSource]: """Returns the parameter value produced by the parser. @@ -2681,7 +2933,12 @@ def consume_value( :meta private: """ # Collect from the parse the value passed by the user to the CLI. - value = opts.get(self.name, UNSET) + value: t.Any = opts.get(self.name, UNSET) + + if value is not UNSET and not self.multiple: + # Use only the last occurrence of the option if multiple isn't enabled. + value = value[-1] + # If the value is set, it means it was sourced from the command line by the # parser, otherwise it left unset by default. source = ( @@ -3223,7 +3480,7 @@ def flag_activation_value(self) -> t.Any: """Value the function receives when this flag is activated on the command line. Resolves a missing :attr:`flag_value` to ``True`` for actual flag options and - ``None`` otherwise. Used by the parser bridge (:meth:`add_to_parser`) and the + ``None`` otherwise. Used by the parser (:meth:`Command.parse_args`) and the runtime (:meth:`consume_value`) so :attr:`flag_value` can keep the :data:`UNSET` sentinel for "did the user pass one?" introspection. """ @@ -3500,48 +3757,6 @@ def _parse_decls( return name, opts, secondary_opts - def add_to_parser(self, parser: _OptionParser, ctx: Context) -> None: - if self.multiple: - action = "append" - elif self.count: - action = "count" - else: - action = "store" - - if self.is_flag: - action = f"{action}_const" - - if self.is_bool_flag and self.secondary_opts: - parser.add_option( - obj=self, opts=self.opts, dest=self.name, action=action, const=True - ) - parser.add_option( - obj=self, - opts=self.secondary_opts, - dest=self.name, - action=action, - const=False, - ) - else: - parser.add_option( - obj=self, - opts=self.opts, - dest=self.name, - action=action, - # ``flag_activation_value`` resolves UNSET to the right parser-store - # constant (``True`` for bool flags) so the raw :attr:`flag_value` - # can keep the sentinel. - const=self.flag_activation_value, - ) - else: - parser.add_option( - obj=self, - opts=self.opts, - dest=self.name, - action=action, - nargs=self.nargs, - ) - def get_help_spec(self, ctx: Context) -> str: """Returns the left column of the option's help record: its spellings and metavar, like ``-v, --verbose`` or ``-c, --config TEXT``. @@ -3803,7 +4018,7 @@ def value_from_envvar(self, ctx: Context) -> t.Any: return rv def consume_value( - self, ctx: Context, opts: cabc.Mapping[str, Parameter] + self, ctx: Context, opts: cabc.Mapping[str, list[t.Any]] ) -> tuple[t.Any, ParameterSource]: """For :class:`Option`, the value can be collected from an interactive prompt if the option is a flag that needs a value (and the :attr:`prompt` property is @@ -3992,9 +4207,6 @@ def get_error_hint(self, ctx: Context | None) -> str: return f"'{self.get_help_spec(ctx)}'" return f"'{self.spec}'" - def add_to_parser(self, parser: _OptionParser, ctx: Context) -> None: - parser.add_argument(dest=self.name, nargs=self.nargs, obj=self) - def __getattr__(name: str) -> object: import warnings diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py index 9cf231499..4720bef01 100644 --- a/src/click/shell_completion.py +++ b/src/click/shell_completion.py @@ -704,7 +704,7 @@ def _resolve_context( """ ctx_args["resilient_parsing"] = True with cli.make_context(prog_name, args.copy(), **ctx_args) as ctx: - args = ctx._protected_args + ctx.args + args = ctx.args while args: command = ctx.command @@ -720,7 +720,7 @@ def _resolve_context( name, args, parent=ctx, resilient_parsing=True ) as sub_ctx: ctx = sub_ctx - args = ctx._protected_args + ctx.args + args = ctx.args else: sub_ctx = ctx @@ -741,8 +741,12 @@ def _resolve_context( sub_ctx = sub_sub_ctx args = sub_ctx.args + # A group resolves its own subcommand from the remaining args. + if isinstance(cmd, Group): + break + ctx = sub_ctx - args = [*sub_ctx._protected_args, *sub_ctx.args] + args = sub_ctx.args else: break diff --git a/tests/test_arguments.py b/tests/test_arguments.py index 2368f12f7..fd6e5987a 100644 --- a/tests/test_arguments.py +++ b/tests/test_arguments.py @@ -1096,6 +1096,17 @@ def cmd(a): assert message in result.stderr +def test_partial_values_for_nargs(runner): + @click.command() + @click.argument("a", nargs=2, type=int, default=(1, 2)) + def cmd(a): + click.echo(repr(a)) + + result = runner.invoke(cmd, ["3"]) + assert result.exception is not None + assert "Argument '[A]...' requires 2 values but 1 was given." in result.output + + def test_multiple_param_decls_not_allowed(runner): with pytest.raises(TypeError): diff --git a/tests/test_basic.py b/tests/test_basic.py index a18574fc4..9911f6aec 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -189,7 +189,7 @@ def sub(): [ ([], "S:[no value]"), (["--s=42"], "S:[42]"), - (["--s"], "Error: Option '--s' requires an argument."), + (["--s"], "Error: Option '--s' requires a value."), (["--s="], "S:[]"), (["--s=\N{SNOWMAN}"], "S:[\N{SNOWMAN}]"), ], diff --git a/tests/test_options.py b/tests/test_options.py index 1d7f7150d..c3612788c 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -2370,14 +2370,26 @@ def __bool__(self) -> Literal[False]: ( # Option default to None. ([], None), - # Config has no default value, and no flag value, so it requires an argument. + # Config has no default value, and no flag value, so it requires a value. ( ["--config"], - re.compile(re.escape("Error: Option '--config' requires an argument.\n")), + re.compile( + re.escape( + "Usage: main [OPTIONS]\n" + "Try 'main --help' for help.\n\n" + "Error: Option '--config' requires a value.\n" + ) + ), ), ( ["--no-config", "--config"], - re.compile(re.escape("Error: Option '--config' requires an argument.\n")), + re.compile( + re.escape( + "Usage: main [OPTIONS]\n" + "Try 'main --help' for help.\n\n" + "Error: Option '--config' requires a value.\n" + ) + ), ), # Passing --no-config defaults to the sentinel value because of the flag_value, # and then the custom type receives that sentinel and returns a message. @@ -2519,11 +2531,17 @@ class Class2: EngineType.OSS, ), # The option has not enough parameters to be detected as flag-like, so it - # requires an argument. + # requires a value. ( {"type": EngineType, "default": EngineType.OSS}, ["--pro"], - re.compile(re.escape("Error: Option '--pro' requires an argument.\n")), + re.compile( + re.escape( + "Usage: scan [OPTIONS]\n" + "Try 'scan --help' for help.\n\n" + "Error: Option '--pro' requires a value.\n" + ) + ), ), ({"type": EngineType, "default": EngineType.OSS}, [], EngineType.OSS), # If a flag value is set, it is returned instead of the default value. diff --git a/tests/test_parser.py b/tests/test_parser.py index f2a3ad593..234dd90ce 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -27,6 +27,19 @@ def test_parser_default_prefixes(): def test_parser_collects_prefixes(): ctx = click.Context(click.Command("test")) parser = _OptionParser(ctx) - click.Option("+p", is_flag=True).add_to_parser(parser, ctx) - click.Option("!e", is_flag=True).add_to_parser(parser, ctx) + p = click.Option("+p", is_flag=True) + e = click.Option("!e", is_flag=True) + parser.add_option(obj=p, opts=p.opts, dest=p.name, action="store_const") + parser.add_option(obj=e, opts=e.opts, dest=e.name, action="store_const") assert parser._opt_prefixes == {"-", "--", "+", "!"} + + +def test_command_collects_prefixes(): + @click.command() + @click.option("+p", is_flag=True) + @click.option("!e", is_flag=True) + def cli(p, e): + pass + + ctx = cli.make_context("cli", []) + assert ctx._opt_prefixes == {"-", "--", "+", "!"} diff --git a/tests/test_termui.py b/tests/test_termui.py index aff5c83d2..9a8432ef1 100644 --- a/tests/test_termui.py +++ b/tests/test_termui.py @@ -1331,7 +1331,7 @@ def test_editor_unclosed_quote(): ("prompt_required", "required", "args", "expect"), [ (True, False, None, "prompt"), - (True, False, ["-v"], "Option '-v' requires an argument."), + (True, False, ["-v"], "Option '-v' requires a value."), (False, True, None, "prompt"), (False, True, ["-v"], "prompt"), ], From 50b6889be925ae4959814d09749f7fcdfaa9a1ff Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:13:06 -0800 Subject: [PATCH 02/18] Rip out old parser. --- CHANGES.md | 10 + docs/api.md | 8 - pyproject.toml | 2 +- src/click/__init__.py | 11 - src/click/parser.py | 505 +------------------------------------ tests/test_deprecations.py | 9 +- tests/test_parser.py | 17 +- uv.lock | 177 ++++++------- 8 files changed, 108 insertions(+), 631 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3e10f5817..2694eefd0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,16 @@ Unreleased +- The old parser, deprecated in 8.2, is removed. {meth}`Command.parse_args` + parses arguments directly. {issue}`2205` + + - `OptionParser` is removed from `click` and `click.parser`, along with + `click.parser.Option`, `Argument`, `ParsingState`, and `normalize_opt`. + Use `optparse` from the standard library if you need the old parser. + - `Command.make_parser` and `Parameter.add_to_parser` are removed. + - `Context.protected_args` always returns an empty list. The subcommand + name and its arguments are in `Context.args`. + - A parameter name that is not a valid Python identifier, or that is a Python keyword, is deprecated and raises `TypeError` in Click 9.0. {pr}`3866` - An {class}`Option` name written as a Python identifier is deprecated when it diff --git a/docs/api.md b/docs/api.md index df62cf5df..4ba578908 100644 --- a/docs/api.md +++ b/docs/api.md @@ -314,14 +314,6 @@ classes and functions. .. autofunction:: wrap_text ``` -## Parsing - -```{eval-rst} -.. autoclass:: OptionParser - :members: - -``` - ## Shell Completion See {doc}`/shell-completion` for information about enabling and diff --git a/pyproject.toml b/pyproject.toml index 9f9461069..530060e3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "click" -version = "8.6.0.dev" +version = "9.0.0.dev" description = "Composable command line interface toolkit" readme = "README.md" license = "BSD-3-Clause" diff --git a/src/click/__init__.py b/src/click/__init__.py index a34ab023a..0a62a4f3d 100644 --- a/src/click/__init__.py +++ b/src/click/__init__.py @@ -98,17 +98,6 @@ def __getattr__(name: str) -> object: ) return _MultiCommand - if name == "OptionParser": - from .parser import _OptionParser - - warnings.warn( - "'OptionParser' is deprecated and will be removed in Click 9.0. The" - " old parser is available in 'optparse'.", - DeprecationWarning, - stacklevel=2, - ) - return _OptionParser - if name == "__version__": import importlib.metadata diff --git a/src/click/parser.py b/src/click/parser.py index 4fcbf7caa..fcfd8c77d 100644 --- a/src/click/parser.py +++ b/src/click/parser.py @@ -1,114 +1,8 @@ -""" -This module started out as largely a copy paste from the stdlib's -optparse module with the features removed that we do not need from -optparse because we implement them in Click on a higher level (for -instance type handling, help formatting and a lot more). - -The plan is to remove more and more from here over time. - -The reason this is a different module and not optparse from the stdlib -is that there are differences in 2.x and 3.x about the error messages -generated and optparse in the stdlib uses gettext for no good reason -and might cause us issues. - -Click uses parts of optparse written by Gregory P. Ward and maintained -by the Python Software Foundation. This is limited to code in parser.py. - -Copyright 2001-2006 Gregory P. Ward. All rights reserved. -Copyright 2002-2006 Python Software Foundation. All rights reserved. -""" - -# This code uses parts of optparse written by Gregory P. Ward and -# maintained by the Python Software Foundation. -# Copyright 2001-2006 Gregory P. Ward -# Copyright 2002-2006 Python Software Foundation from __future__ import annotations -import collections.abc as cabc -import typing as t -from collections import deque -from gettext import gettext as _ -from gettext import ngettext - -from ._utils import FLAG_NEEDS_VALUE -from ._utils import UNSET -from .exceptions import BadArgumentUsage -from .exceptions import BadOptionUsage -from .exceptions import NoSuchOption -from .exceptions import UsageError - -if t.TYPE_CHECKING: - from ._utils import T_FLAG_NEEDS_VALUE - from ._utils import T_UNSET - from .core import Argument as CoreArgument - from .core import Context - from .core import Option as CoreOption - from .core import Parameter as CoreParameter - -V = t.TypeVar("V") - - -def _unpack_args( - args: cabc.Sequence[str], nargs_spec: cabc.Sequence[int] -) -> 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. - - The nargs specification is the number of arguments that should be consumed - or `-1` to indicate that this position should eat up all the remainders. - - Missing items are filled with ``UNSET``. - """ - args = deque(args) - nargs_spec = deque(nargs_spec) - rv: list[str | tuple[str | T_UNSET, ...] | T_UNSET] = [] - spos: int | None = None - - def _fetch(c: deque[str]) -> str | T_UNSET: - try: - if spos is None: - return c.popleft() - else: - return c.pop() - except IndexError: - return UNSET - - while nargs_spec: - if spos is None: - nargs = nargs_spec.popleft() - else: - nargs = nargs_spec.pop() - - if nargs == 1: - rv.append(_fetch(args)) - elif nargs > 1: - 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. - if spos is not None: - x.reverse() - - rv.append(tuple(x)) - elif nargs < 0: - if spos is not None: - raise TypeError("Cannot have two nargs < 0") - - spos = len(rv) - rv.append(UNSET) - - # spos is the position of the wildcard (star). If it's not `None`, - # we fill it with the remainder. - if spos is not None: - rv[spos] = tuple(args) - args = [] - rv[spos + 1 :] = reversed(rv[spos + 1 :]) - - return tuple(rv), list(args) - def _split_opt(opt: str) -> tuple[str, str]: + """Splits an option into a prefix and a value.""" first = opt[:1] if first.isalnum(): return "", opt @@ -117,407 +11,16 @@ def _split_opt(opt: str) -> tuple[str, str]: return first, opt[1:] -def _normalize_opt(opt: str, ctx: Context | None) -> str: - if ctx is None or ctx.token_normalize_func is None: - return opt - prefix, opt = _split_opt(opt) - return f"{prefix}{ctx.token_normalize_func(opt)}" - - -class _Option: - def __init__( - self, - obj: CoreOption, - opts: cabc.Sequence[str], - dest: str | None, - action: str | None = None, - nargs: int = 1, - const: t.Any | None = None, - ): - self._short_opts = [] - self._long_opts = [] - self.prefixes: set[str] = set() - - for opt in opts: - prefix, value = _split_opt(opt) - if not prefix: - 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) - else: - self._long_opts.append(opt) - self.prefixes.add(prefix) - - if action is None: - action = "store" - - self.dest = dest - self.action = action - self.nargs = nargs - self.const = const - self.obj = obj - - @property - def takes_value(self) -> bool: - return self.action in ("store", "append") - - def process(self, value: t.Any, state: _ParsingState) -> None: - if self.action == "store": - state.opts[self.dest] = value # type: ignore - elif self.action == "store_const": - state.opts[self.dest] = self.const # type: ignore - elif self.action == "append": - state.opts.setdefault(self.dest, []).append(value) # type: ignore - elif self.action == "append_const": - state.opts.setdefault(self.dest, []).append(self.const) # type: ignore - elif self.action == "count": - state.opts[self.dest] = state.opts.get(self.dest, 0) + 1 # type: ignore - else: - raise ValueError(f"unknown action '{self.action}'") - state.order.append(self.obj) - - -class _Argument: - def __init__(self, obj: CoreArgument, dest: str | None, nargs: int = 1): - self.dest = dest - self.nargs = nargs - self.obj = obj - - def process( - self, - value: str | cabc.Sequence[str | T_UNSET] | T_UNSET, - state: _ParsingState, - ) -> None: - if self.nargs > 1: - assert isinstance(value, cabc.Sequence) - holes = sum(x is UNSET for x in value) - if holes == len(value): - value = UNSET - elif holes != 0: - raise BadArgumentUsage( - _("Argument {name!r} takes {nargs} values.").format( - name=self.dest, nargs=self.nargs - ) - ) - - # We failed to collect any argument value so we consider the argument as unset. - if value == (): - value = UNSET - - state.opts[self.dest] = value # type: ignore - state.order.append(self.obj) - - -class _ParsingState: - def __init__(self, rargs: list[str]) -> None: - self.opts: dict[str, t.Any] = {} - self.largs: list[str] = [] - self.rargs = rargs - self.order: list[CoreParameter] = [] - - -class _OptionParser: - """The option parser is an internal class that is ultimately used to - parse options and arguments. It's modelled after optparse and brings - a similar but vastly simplified API. It should generally not be used - directly as the high level Click classes wrap it for you. - - It's not nearly as extensible as optparse or argparse as it does not - implement features that are implemented on a higher level (such as - types or defaults). - - :param ctx: optionally the :class:`~click.Context` where this parser - should go with. - - .. deprecated:: 8.2 - Will be removed in Click 9.0. - """ - - def __init__(self, ctx: Context | None = None) -> None: - #: The :class:`~click.Context` for this parser. This might be - #: `None` for some advanced use cases. - self.ctx = ctx - #: This controls how the parser deals with interspersed arguments. - #: If this is set to `False`, the parser will stop on the first - #: non-option. Click uses this to implement nested subcommands - #: safely. - self.allow_interspersed_args: bool = True - #: This tells the parser how to deal with unknown options. By - #: default it will error out (which is sensible), but there is a - #: second mode where it will ignore it and continue processing - #: after shifting all the unknown options into the resulting args. - self.ignore_unknown_options: bool = False - - if ctx is not None: - self.allow_interspersed_args = ctx.allow_interspersed_args - self.ignore_unknown_options = ctx.ignore_unknown_options - - self._short_opt: dict[str, _Option] = {} - self._long_opt: dict[str, _Option] = {} - self._opt_prefixes = {"-", "--"} - self._args: list[_Argument] = [] - - def add_option( - self, - obj: CoreOption, - opts: cabc.Sequence[str], - dest: str | None, - action: str | None = None, - nargs: int = 1, - const: t.Any | None = None, - ) -> None: - """Adds a new option named `dest` to the parser. The destination - is not inferred (unlike with optparse) and needs to be explicitly - provided. Action can be any of ``store``, ``store_const``, - ``append``, ``append_const`` or ``count``. - - The `obj` can be used to identify the option in the order list - that is returned from the parser. - """ - opts = [_normalize_opt(opt, self.ctx) for opt in opts] - option = _Option(obj, opts, dest, action=action, nargs=nargs, const=const) - self._opt_prefixes.update(option.prefixes) - for opt in option._short_opts: - self._short_opt[opt] = option - for opt in option._long_opts: - self._long_opt[opt] = option - - def add_argument(self, obj: CoreArgument, dest: str | None, nargs: int = 1) -> None: - """Adds a positional argument named `dest` to the parser. - - The `obj` can be used to identify the option in the order list - that is returned from the parser. - """ - self._args.append(_Argument(obj, dest=dest, nargs=nargs)) - - def parse_args( - self, args: list[str] - ) -> tuple[dict[str, t.Any], list[str], list[CoreParameter]]: - """Parses positional arguments and returns ``(values, args, order)`` - for the parsed options and arguments as well as the leftover - arguments if there are any. The order is a list of objects as they - appear on the command line. If arguments appear multiple times they - will be memorized multiple times as well. - """ - state = _ParsingState(args) - try: - self._process_args_for_options(state) - self._process_args_for_args(state) - except UsageError: - if self.ctx is None or not self.ctx.resilient_parsing: - raise - return state.opts, state.largs, state.order - - def _process_args_for_args(self, state: _ParsingState) -> None: - pargs, args = _unpack_args( - state.largs + state.rargs, [x.nargs for x in self._args] - ) - - for idx, arg in enumerate(self._args): - arg.process(pargs[idx], state) - - state.largs = args - state.rargs = [] - - def _process_args_for_options(self, state: _ParsingState) -> None: - while state.rargs: - arg = state.rargs.pop(0) - arglen = len(arg) - # Double dashes always handled explicitly regardless of what - # prefixes are valid. - if arg == "--": - return - elif arg[:1] in self._opt_prefixes and arglen > 1: - self._process_opts(arg, state) - elif self.allow_interspersed_args: - state.largs.append(arg) - else: - state.rargs.insert(0, arg) - return - - # Say this is the original argument list: - # [arg0, arg1, ..., arg(i-1), arg(i), arg(i+1), ..., arg(N-1)] - # ^ - # (we are about to process arg(i)). - # - # Then rargs is [arg(i), ..., arg(N-1)] and largs is a *subset* of - # [arg0, ..., arg(i-1)] (any options and their arguments will have - # been removed from largs). - # - # The while loop will usually consume 1 or more arguments per pass. - # If it consumes 1 (eg. arg is an option that takes no arguments), - # then after _process_arg() is done the situation is: - # - # largs = subset of [arg0, ..., arg(i)] - # rargs = [arg(i+1), ..., arg(N-1)] - # - # If allow_interspersed_args is false, largs will always be - # *empty* -- still a subset of [arg0, ..., arg(i-1)], but - # not a very interesting subset! - - def _match_long_opt( - self, opt: str, explicit_value: str | None, state: _ParsingState - ) -> None: - if opt not in self._long_opt: - raise NoSuchOption(opt, possibilities=self._long_opt, ctx=self.ctx) - - option = self._long_opt[opt] - if option.takes_value: - # At this point it's safe to modify rargs by injecting the - # explicit value, because no exception is raised in this - # branch. This means that the inserted value will be fully - # consumed. - if explicit_value is not None: - state.rargs.insert(0, explicit_value) - - value = self._get_value_from_state(opt, option, state) - - elif explicit_value is not None: - raise BadOptionUsage( - opt, _("Option {name!r} does not take a value.").format(name=opt) - ) - - else: - value = UNSET - - option.process(value, state) - - def _match_short_opt(self, arg: str, state: _ParsingState) -> None: - stop = False - i = 1 - prefix = arg[0] - unknown_options = [] - - for ch in arg[1:]: - opt = _normalize_opt(f"{prefix}{ch}", self.ctx) - option = self._short_opt.get(opt) - i += 1 - - if not option: - if self.ignore_unknown_options: - unknown_options.append(ch) - continue - raise NoSuchOption(opt, ctx=self.ctx) - if option.takes_value: - # Any characters left in arg? Pretend they're the - # next arg, and stop consuming characters of arg. - if i < len(arg): - state.rargs.insert(0, arg[i:]) - stop = True - - value = self._get_value_from_state(opt, option, state) - - else: - value = UNSET - - option.process(value, state) - - if stop: - break - - # 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 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_UNSET | T_FLAG_NEEDS_VALUE: - nargs = option.nargs - - value: str | cabc.Sequence[str] | T_UNSET | T_FLAG_NEEDS_VALUE - - if len(state.rargs) < nargs: - if option.obj._flag_needs_value: - # Option allows omitting the value. - value = FLAG_NEEDS_VALUE - else: - raise BadOptionUsage( - option_name, - ngettext( - "Option {name!r} requires an argument.", - "Option {name!r} requires {nargs} arguments.", - nargs, - ).format(name=option_name, nargs=nargs), - ) - elif nargs == 1: - next_rarg = state.rargs[0] - - if ( - option.obj._flag_needs_value - and isinstance(next_rarg, str) - and next_rarg[:1] in self._opt_prefixes - and len(next_rarg) > 1 - ): - # The next arg looks like the start of an option, don't - # use it as the value if omitting the value is allowed. - value = FLAG_NEEDS_VALUE - else: - value = state.rargs.pop(0) - else: - value = tuple(state.rargs[:nargs]) - del state.rargs[:nargs] - - return value - - def _process_opts(self, arg: str, state: _ParsingState) -> None: - explicit_value = None - # Long option handling happens in two parts. The first part is - # supporting explicitly attached values. In any case, we will try - # to long match the option first. - if "=" in arg: - long_opt, explicit_value = arg.split("=", 1) - else: - long_opt = arg - norm_long_opt = _normalize_opt(long_opt, self.ctx) - - # At this point we will match the (assumed) long option through - # the long option matching code. Note that this allows options - # like "-foo" to be matched as long options. - try: - self._match_long_opt(norm_long_opt, explicit_value, state) - except NoSuchOption: - # At this point the long option matching failed, and we need - # to try with short options. However there is a special rule - # which says, that if we have a two character options prefix - # (applies to "--foo" for instance), we do not dispatch to the - # short option code and will instead raise the no option - # error. - if arg[:2] not in self._opt_prefixes: - self._match_short_opt(arg, state) - return - - if not self.ignore_unknown_options: - raise - - state.largs.append(arg) - - def __getattr__(name: str) -> object: import warnings - if name in { - "OptionParser", - "Argument", - "Option", - "split_opt", - "normalize_opt", - "ParsingState", - }: + if name == "split_opt": warnings.warn( - f"'parser.{name}' is deprecated and will be removed in Click 9.0." - " The old parser is available in 'optparse'.", + "'parser.split_opt' is deprecated and will be removed in Click 9.0.", DeprecationWarning, stacklevel=2, ) - return globals()[f"_{name}"] + return _split_opt if name == "split_arg_string": from .shell_completion import split_arg_string diff --git a/tests/test_deprecations.py b/tests/test_deprecations.py index 231dd6103..72468d8ec 100644 --- a/tests/test_deprecations.py +++ b/tests/test_deprecations.py @@ -23,15 +23,8 @@ (click, "MultiCommand", click.core._MultiCommand), (click.core, "BaseCommand", click.core._BaseCommand), (click.core, "MultiCommand", click.core._MultiCommand), - # Old parser API (moved to `optparse`); `OptionParser` is also - # re-exported from the top-level `click` namespace. - (click, "OptionParser", click.parser._OptionParser), - (click.parser, "OptionParser", click.parser._OptionParser), - (click.parser, "Argument", click.parser._Argument), - (click.parser, "Option", click.parser._Option), + # Remaining `click.parser` helpers. (click.parser, "split_opt", click.parser._split_opt), - (click.parser, "normalize_opt", click.parser._normalize_opt), - (click.parser, "ParsingState", click.parser._ParsingState), (click.parser, "split_arg_string", click.shell_completion.split_arg_string), # Deprecated `click.utils` utilities. (click.utils, "LazyFile", click.utils._LazyFile), diff --git a/tests/test_parser.py b/tests/test_parser.py index 234dd90ce..9745e450f 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1,7 +1,6 @@ import pytest import click -from click.parser import _OptionParser from click.shell_completion import split_arg_string @@ -19,19 +18,9 @@ def test_split_arg_string(value, expect): assert split_arg_string(value) == expect -def test_parser_default_prefixes(): - parser = _OptionParser() - assert parser._opt_prefixes == {"-", "--"} - - -def test_parser_collects_prefixes(): - ctx = click.Context(click.Command("test")) - parser = _OptionParser(ctx) - p = click.Option("+p", is_flag=True) - e = click.Option("!e", is_flag=True) - parser.add_option(obj=p, opts=p.opts, dest=p.name, action="store_const") - parser.add_option(obj=e, opts=e.opts, dest=e.name, action="store_const") - assert parser._opt_prefixes == {"-", "--", "+", "!"} +def test_command_default_prefixes(): + ctx = click.Command("cli").make_context("cli", []) + assert ctx._opt_prefixes == {"-", "--"} def test_command_collects_prefixes(): diff --git a/uv.lock b/uv.lock index 75e6844f3..2b8673c0e 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 3 +revision = 5 requires-python = ">=3.10" resolution-markers = [ "python_full_version >= '3.12'", @@ -173,8 +173,9 @@ wheels = [ [[package]] name = "click" -version = "8.6.0.dev0" +version = "9.0.0.dev0" source = { editable = "." } +default-groups = ["dev", "pre-commit", "tests", "typing"] [package.dev-dependencies] dev = [ @@ -298,7 +299,7 @@ name = "exceptiongroup" version = "1.3.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "typing-extensions", marker = "python_full_version < '3.11'" }, + { name = "typing-extensions" }, ] sdist = { url = "https://files.pythonhosted.org/packages/50/79/66800aadf48771f6b62f7eb014e352e5d06856655206165d775e675a02c9/exceptiongroup-1.3.1.tar.gz", hash = "sha256:8b412432c6055b0b7d14c310000ae93352ed6754f70fa8f7c34141f91c4e3219", size = 30371, upload-time = "2025-11-21T23:01:54.787Z" } wheels = [ @@ -328,8 +329,8 @@ name = "gha-update" version = "0.2.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "click", marker = "python_full_version >= '3.12'" }, - { name = "httpx", marker = "python_full_version >= '3.12'" }, + { name = "click" }, + { name = "httpx" }, ] sdist = { url = "https://files.pythonhosted.org/packages/46/e8/eb710e08998a22b314cc068f14805cfdd12e3934a5496c8916c5a164c65a/gha_update-0.2.0.tar.gz", hash = "sha256:328ee0db09346ad13ee90646698cea2ec1f9035964ddd7c2a728a91034c3f4b0", size = 4756, upload-time = "2025-07-14T03:13:33.254Z" } wheels = [ @@ -350,8 +351,8 @@ name = "httpcore" version = "1.0.9" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "certifi", marker = "python_full_version >= '3.12'" }, - { name = "h11", marker = "python_full_version >= '3.12'" }, + { name = "certifi" }, + { name = "h11" }, ] sdist = { url = "https://files.pythonhosted.org/packages/06/94/82699a10bca87a5556c9c59b5963f2d039dbd239f25bc2a63907a05a14cb/httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8", size = 85484, upload-time = "2025-04-24T22:06:22.219Z" } wheels = [ @@ -363,10 +364,10 @@ name = "httpx" version = "0.28.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "anyio", marker = "python_full_version >= '3.12'" }, - { name = "certifi", marker = "python_full_version >= '3.12'" }, - { name = "httpcore", marker = "python_full_version >= '3.12'" }, - { name = "idna", marker = "python_full_version >= '3.12'" }, + { name = "anyio" }, + { name = "certifi" }, + { name = "httpcore" }, + { name = "idna" }, ] sdist = { url = "https://files.pythonhosted.org/packages/b1/df/48c586a5fe32a0f01324ee087459e112ebb7224f646c0b5023f5e79e9956/httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc", size = 141406, upload-time = "2024-12-06T15:37:23.222Z" } wheels = [ @@ -514,7 +515,7 @@ resolution-markers = [ "python_full_version < '3.11'", ] dependencies = [ - { name = "mdurl", marker = "python_full_version < '3.11'" }, + { name = "mdurl" }, ] sdist = { url = "https://files.pythonhosted.org/packages/38/71/3b932df36c1a044d397a1f92d1cf91ee0a503d91e470cbd670aa66b07ed0/markdown-it-py-3.0.0.tar.gz", hash = "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb", size = 74596, upload-time = "2023-06-03T06:41:14.443Z" } wheels = [ @@ -530,7 +531,7 @@ resolution-markers = [ "python_full_version == '3.11.*'", ] dependencies = [ - { name = "mdurl", marker = "python_full_version >= '3.11'" }, + { name = "mdurl" }, ] sdist = { url = "https://files.pythonhosted.org/packages/5b/f5/4ec618ed16cc4f8fb3b701563655a69816155e79e24a17b651541804721d/markdown_it_py-4.0.0.tar.gz", hash = "sha256:cb0a2b4aa34f932c007117b194e945bd74e0ec24133ceb5bac59009cda1cb9f3", size = 73070, upload-time = "2025-08-11T12:57:52.854Z" } wheels = [ @@ -719,12 +720,12 @@ resolution-markers = [ "python_full_version < '3.11'", ] dependencies = [ - { name = "docutils", version = "0.21.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "jinja2", marker = "python_full_version < '3.11'" }, - { name = "markdown-it-py", version = "3.0.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "mdit-py-plugins", marker = "python_full_version < '3.11'" }, - { name = "pyyaml", marker = "python_full_version < '3.11'" }, - { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, + { name = "docutils", version = "0.21.2", source = { registry = "https://pypi.org/simple" } }, + { name = "jinja2" }, + { name = "markdown-it-py", version = "3.0.0", source = { registry = "https://pypi.org/simple" } }, + { name = "mdit-py-plugins" }, + { name = "pyyaml" }, + { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" } }, ] sdist = { url = "https://files.pythonhosted.org/packages/66/a5/9626ba4f73555b3735ad86247a8077d4603aa8628537687c839ab08bfe44/myst_parser-4.0.1.tar.gz", hash = "sha256:5cfea715e4f3574138aecbf7d54132296bfd72bb614d31168f48c477a830a7c4", size = 93985, upload-time = "2025-02-12T10:53:03.833Z" } wheels = [ @@ -740,12 +741,12 @@ resolution-markers = [ "python_full_version == '3.11.*'", ] dependencies = [ - { name = "docutils", version = "0.22.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, - { name = "jinja2", marker = "python_full_version >= '3.11'" }, - { name = "markdown-it-py", version = "4.0.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, - { name = "mdit-py-plugins", marker = "python_full_version >= '3.11'" }, - { name = "pyyaml", marker = "python_full_version >= '3.11'" }, - { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" }, + { name = "docutils", version = "0.22.4", source = { registry = "https://pypi.org/simple" } }, + { name = "jinja2" }, + { name = "markdown-it-py", version = "4.0.0", source = { registry = "https://pypi.org/simple" } }, + { name = "mdit-py-plugins" }, + { name = "pyyaml" }, + { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, { name = "sphinx", version = "9.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/33/fa/7b45eef11b7971f0beb29d27b7bfe0d747d063aa29e170d9edd004733c8a/myst_parser-5.0.0.tar.gz", hash = "sha256:f6f231452c56e8baa662cc352c548158f6a16fcbd6e3800fc594978002b94f3a", size = 98535, upload-time = "2026-01-15T09:08:18.036Z" } @@ -1064,23 +1065,23 @@ resolution-markers = [ "python_full_version < '3.11'", ] dependencies = [ - { name = "alabaster", marker = "python_full_version < '3.11'" }, - { name = "babel", marker = "python_full_version < '3.11'" }, - { name = "colorama", marker = "python_full_version < '3.11' and sys_platform == 'win32'" }, - { name = "docutils", version = "0.21.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "imagesize", marker = "python_full_version < '3.11'" }, - { name = "jinja2", marker = "python_full_version < '3.11'" }, - { name = "packaging", marker = "python_full_version < '3.11'" }, - { name = "pygments", marker = "python_full_version < '3.11'" }, - { name = "requests", marker = "python_full_version < '3.11'" }, - { name = "snowballstemmer", marker = "python_full_version < '3.11'" }, - { name = "sphinxcontrib-applehelp", marker = "python_full_version < '3.11'" }, - { name = "sphinxcontrib-devhelp", marker = "python_full_version < '3.11'" }, - { name = "sphinxcontrib-htmlhelp", marker = "python_full_version < '3.11'" }, - { name = "sphinxcontrib-jsmath", marker = "python_full_version < '3.11'" }, - { name = "sphinxcontrib-qthelp", marker = "python_full_version < '3.11'" }, - { name = "sphinxcontrib-serializinghtml", marker = "python_full_version < '3.11'" }, - { name = "tomli", marker = "python_full_version < '3.11'" }, + { name = "alabaster" }, + { name = "babel" }, + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "docutils", version = "0.21.2", source = { registry = "https://pypi.org/simple" } }, + { name = "imagesize" }, + { name = "jinja2" }, + { name = "packaging" }, + { name = "pygments" }, + { name = "requests" }, + { name = "snowballstemmer" }, + { name = "sphinxcontrib-applehelp" }, + { name = "sphinxcontrib-devhelp" }, + { name = "sphinxcontrib-htmlhelp" }, + { name = "sphinxcontrib-jsmath" }, + { name = "sphinxcontrib-qthelp" }, + { name = "sphinxcontrib-serializinghtml" }, + { name = "tomli" }, ] sdist = { url = "https://files.pythonhosted.org/packages/6f/6d/be0b61178fe2cdcb67e2a92fc9ebb488e3c51c4f74a36a7824c0adf23425/sphinx-8.1.3.tar.gz", hash = "sha256:43c1911eecb0d3e161ad78611bc905d1ad0e523e4ddc202a58a821773dc4c927", size = 8184611, upload-time = "2024-10-13T20:27:13.93Z" } wheels = [ @@ -1095,23 +1096,23 @@ resolution-markers = [ "python_full_version == '3.11.*'", ] dependencies = [ - { name = "alabaster", marker = "python_full_version == '3.11.*'" }, - { name = "babel", marker = "python_full_version == '3.11.*'" }, - { name = "colorama", marker = "python_full_version == '3.11.*' and sys_platform == 'win32'" }, - { name = "docutils", version = "0.22.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" }, - { name = "imagesize", marker = "python_full_version == '3.11.*'" }, - { name = "jinja2", marker = "python_full_version == '3.11.*'" }, - { name = "packaging", marker = "python_full_version == '3.11.*'" }, - { name = "pygments", marker = "python_full_version == '3.11.*'" }, - { name = "requests", marker = "python_full_version == '3.11.*'" }, - { name = "roman-numerals", marker = "python_full_version == '3.11.*'" }, - { name = "snowballstemmer", marker = "python_full_version == '3.11.*'" }, - { name = "sphinxcontrib-applehelp", marker = "python_full_version == '3.11.*'" }, - { name = "sphinxcontrib-devhelp", marker = "python_full_version == '3.11.*'" }, - { name = "sphinxcontrib-htmlhelp", marker = "python_full_version == '3.11.*'" }, - { name = "sphinxcontrib-jsmath", marker = "python_full_version == '3.11.*'" }, - { name = "sphinxcontrib-qthelp", marker = "python_full_version == '3.11.*'" }, - { name = "sphinxcontrib-serializinghtml", marker = "python_full_version == '3.11.*'" }, + { name = "alabaster" }, + { name = "babel" }, + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "docutils", version = "0.22.4", source = { registry = "https://pypi.org/simple" } }, + { name = "imagesize" }, + { name = "jinja2" }, + { name = "packaging" }, + { name = "pygments" }, + { name = "requests" }, + { name = "roman-numerals" }, + { name = "snowballstemmer" }, + { name = "sphinxcontrib-applehelp" }, + { name = "sphinxcontrib-devhelp" }, + { name = "sphinxcontrib-htmlhelp" }, + { name = "sphinxcontrib-jsmath" }, + { name = "sphinxcontrib-qthelp" }, + { name = "sphinxcontrib-serializinghtml" }, ] sdist = { url = "https://files.pythonhosted.org/packages/42/50/a8c6ccc36d5eacdfd7913ddccd15a9cee03ecafc5ee2bc40e1f168d85022/sphinx-9.0.4.tar.gz", hash = "sha256:594ef59d042972abbc581d8baa577404abe4e6c3b04ef61bd7fc2acbd51f3fa3", size = 8710502, upload-time = "2025-12-04T07:45:27.343Z" } wheels = [ @@ -1126,23 +1127,23 @@ resolution-markers = [ "python_full_version >= '3.12'", ] dependencies = [ - { name = "alabaster", marker = "python_full_version >= '3.12'" }, - { name = "babel", marker = "python_full_version >= '3.12'" }, - { name = "colorama", marker = "python_full_version >= '3.12' and sys_platform == 'win32'" }, - { name = "docutils", version = "0.22.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" }, - { name = "imagesize", marker = "python_full_version >= '3.12'" }, - { name = "jinja2", marker = "python_full_version >= '3.12'" }, - { name = "packaging", marker = "python_full_version >= '3.12'" }, - { name = "pygments", marker = "python_full_version >= '3.12'" }, - { name = "requests", marker = "python_full_version >= '3.12'" }, - { name = "roman-numerals", marker = "python_full_version >= '3.12'" }, - { name = "snowballstemmer", marker = "python_full_version >= '3.12'" }, - { name = "sphinxcontrib-applehelp", marker = "python_full_version >= '3.12'" }, - { name = "sphinxcontrib-devhelp", marker = "python_full_version >= '3.12'" }, - { name = "sphinxcontrib-htmlhelp", marker = "python_full_version >= '3.12'" }, - { name = "sphinxcontrib-jsmath", marker = "python_full_version >= '3.12'" }, - { name = "sphinxcontrib-qthelp", marker = "python_full_version >= '3.12'" }, - { name = "sphinxcontrib-serializinghtml", marker = "python_full_version >= '3.12'" }, + { name = "alabaster" }, + { name = "babel" }, + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "docutils", version = "0.22.4", source = { registry = "https://pypi.org/simple" } }, + { name = "imagesize" }, + { name = "jinja2" }, + { name = "packaging" }, + { name = "pygments" }, + { name = "requests" }, + { name = "roman-numerals" }, + { name = "snowballstemmer" }, + { name = "sphinxcontrib-applehelp" }, + { name = "sphinxcontrib-devhelp" }, + { name = "sphinxcontrib-htmlhelp" }, + { name = "sphinxcontrib-jsmath" }, + { name = "sphinxcontrib-qthelp" }, + { name = "sphinxcontrib-serializinghtml" }, ] sdist = { url = "https://files.pythonhosted.org/packages/cd/bd/f08eb0f4eed5c83f1ba2a3bd18f7745a2b1525fad70660a1c00224ec468a/sphinx-9.1.0.tar.gz", hash = "sha256:7741722357dd75f8190766926071fed3bdc211c74dd2d7d4df5404da95930ddb", size = 8718324, upload-time = "2025-12-31T15:09:27.646Z" } wheels = [ @@ -1157,12 +1158,12 @@ resolution-markers = [ "python_full_version < '3.11'", ] dependencies = [ - { name = "colorama", marker = "python_full_version < '3.11'" }, - { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "starlette", marker = "python_full_version < '3.11'" }, - { name = "uvicorn", marker = "python_full_version < '3.11'" }, - { name = "watchfiles", marker = "python_full_version < '3.11'" }, - { name = "websockets", marker = "python_full_version < '3.11'" }, + { name = "colorama" }, + { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" } }, + { name = "starlette" }, + { name = "uvicorn" }, + { name = "watchfiles" }, + { name = "websockets" }, ] sdist = { url = "https://files.pythonhosted.org/packages/a5/2c/155e1de2c1ba96a72e5dba152c509a8b41e047ee5c2def9e9f0d812f8be7/sphinx_autobuild-2024.10.3.tar.gz", hash = "sha256:248150f8f333e825107b6d4b86113ab28fa51750e5f9ae63b59dc339be951fb1", size = 14023, upload-time = "2024-10-02T23:15:30.172Z" } wheels = [ @@ -1178,13 +1179,13 @@ resolution-markers = [ "python_full_version == '3.11.*'", ] dependencies = [ - { name = "colorama", marker = "python_full_version >= '3.11'" }, - { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" }, + { name = "colorama" }, + { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, { name = "sphinx", version = "9.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" }, - { name = "starlette", marker = "python_full_version >= '3.11'" }, - { name = "uvicorn", marker = "python_full_version >= '3.11'" }, - { name = "watchfiles", marker = "python_full_version >= '3.11'" }, - { name = "websockets", marker = "python_full_version >= '3.11'" }, + { name = "starlette" }, + { name = "uvicorn" }, + { name = "watchfiles" }, + { name = "websockets" }, ] sdist = { url = "https://files.pythonhosted.org/packages/e0/3c/a59a3a453d4133777f7ed2e83c80b7dc817d43c74b74298ca0af869662ad/sphinx_autobuild-2025.8.25.tar.gz", hash = "sha256:9cf5aab32853c8c31af572e4fecdc09c997e2b8be5a07daf2a389e270e85b213", size = 15200, upload-time = "2025-08-25T18:44:55.436Z" } wheels = [ From 6ca1f700e9d8c79517b04f6b004d92f6271c9183 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:40:41 -0800 Subject: [PATCH 03/18] Add test cases to cover corner cases. --- tests/test_basic.py | 51 ++++++++++++++++++++++++++++++++++ tests/test_commands.py | 62 ++++++++++++++++++++++++++++++++++++++++++ tests/test_options.py | 61 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) diff --git a/tests/test_basic.py b/tests/test_basic.py index 9911f6aec..cc421c78d 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -310,6 +310,57 @@ def cli(on): assert result.return_value is expect +@pytest.mark.parametrize( + ("args", "expect"), + [ + (["-s"], True), + (["-S"], False), + (["--no-shout"], False), + # The last occurrence wins, whichever name is used. + (["-s", "-S"], False), + # Short and long names map to the same option. + (["-S", "--shout"], True), + # Switching back and forth between names, an "on" name doesn't stick. + (["--no-shout", "-s", "--no-shout"], False), + # Bundled short names are read in order, the last one wins. + (["-sS"], False), + (["-Ss"], True), + ], +) +def test_boolean_switch_secondary_names(runner, args, expect): + @click.command() + @click.option("-s/-S", "--shout/--no-shout", default=None) + def cli(shout): + return shout + + result = runner.invoke(cli, args, standalone_mode=False, catch_exceptions=False) + assert result.return_value is expect + + +@pytest.mark.parametrize( + ("args", "expect"), [(["--SHOUT"], True), (["--No-Shout"], False)] +) +def test_boolean_switch_secondary_names_normalized(runner, args, expect): + @click.command(context_settings={"token_normalize_func": str.lower}) + @click.option("--shout/--no-shout", default=None) + def cli(shout): + return shout + + result = runner.invoke(cli, args, standalone_mode=False, catch_exceptions=False) + assert result.return_value is expect + + +def test_boolean_switch_secondary_does_not_take_value(runner): + @click.command() + @click.option("--shout/--no-shout") + def cli(shout): + pass + + result = runner.invoke(cli, ["--no-shout=1"]) + assert result.exit_code == 2 + assert "Option '--no-shout' does not take a value." in result.output + + @pytest.mark.parametrize( ("default", "args", "expect"), ( diff --git a/tests/test_commands.py b/tests/test_commands.py index 81d600edb..2f3a9c87c 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -549,6 +549,68 @@ def cli(verbose, args): ] +@pytest.mark.parametrize( + ("interspersed", "args", "expect"), + [ + (True, ["a", "-v", "b"], (True, ("a", "b"))), + (True, ["-v", "a", "b"], (True, ("a", "b"))), + (False, ["-v", "a", "b"], (True, ("a", "b"))), + (False, ["a", "-v", "b"], (False, ("a", "-v", "b"))), + # Parsing stops at the first positional, so the later known option isn't + # parsed and the unknown one isn't an error. Groups rely on this to pass + # a subcommand's options through untouched. + (False, ["-v", "a", "-v", "--nope"], (True, ("a", "-v", "--nope"))), + ], +) +def test_allow_interspersed_args(runner, interspersed, args, expect): + @click.command(context_settings={"allow_interspersed_args": interspersed}) + @click.option("-v", is_flag=True) + @click.argument("args", nargs=-1) + def cli(v, args): + return v, args + + result = runner.invoke(cli, args, standalone_mode=False, catch_exceptions=False) + assert result.return_value == expect + + +@pytest.mark.parametrize( + ("args", "params", "extra"), + [ + pytest.param(["-a", "--nope"], {"opt": None, "point": None}, [], id="unknown"), + pytest.param( + ["-a", "--opt"], {"opt": None, "point": None}, [], id="missing value" + ), + pytest.param( + ["-a", "--flag=1"], {"opt": None, "point": None}, [], id="flag value" + ), + pytest.param( + ["-a", "1"], {"opt": None, "point": None}, ["1"], id="partial nargs" + ), + pytest.param( + ["-a", "1", "2", "3"], + {"opt": None, "point": ("1", "2")}, + ["3"], + id="extra args", + ), + ], +) +def test_resilient_parsing_suppresses_usage_errors(args, params, extra): + @click.command() + @click.option("-a", is_flag=True) + @click.option("--opt") + @click.option("--flag", is_flag=True) + @click.argument("point", nargs=2, required=False) + def cli(a, opt, flag, point): + pass + + with pytest.raises(click.UsageError): + cli.make_context("cli", args.copy()) + + ctx = cli.make_context("cli", args, resilient_parsing=True) + assert ctx.params == {"a": True, "flag": False, **params} + assert ctx.args == extra + + @pytest.mark.parametrize("doc", ["CLI HELP", None]) @pytest.mark.parametrize("deprecated", [True, "USE OTHER COMMAND INSTEAD"]) def test_deprecated_in_help_messages(runner, doc, deprecated): diff --git a/tests/test_options.py b/tests/test_options.py index c3612788c..ce5c3e14e 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -229,6 +229,67 @@ def test_suggest_possible_options(runner, value, expect): assert expect in result.output +@pytest.mark.parametrize( + "opt_params", [{"is_flag": True}, {"count": True}], ids=["flag", "count"] +) +def test_flag_does_not_take_value(runner, opt_params): + @click.command() + @click.option("--flag", **opt_params) + def cli(flag): + pass + + result = runner.invoke(cli, ["--flag=value"]) + assert result.exit_code == 2 + assert "Error: Option '--flag' does not take a value." in result.output + + +@pytest.mark.parametrize( + ("nargs", "args", "expect"), + [ + (2, ["--point", "1"], "Option '--point' requires 2 values but 1 was given."), + ( + 3, + ["--point", "1", "2"], + "Option '--point' requires 3 values but 2 were given.", + ), + (3, ["--point=1", "2"], "Option '--point' requires 3 values but 2 were given."), + (2, ["-p1"], "Option '-p' requires 2 values but 1 was given."), + (2, ["--point"], "Option '--point' requires 2 values."), + ], +) +def test_nargs_too_few_values(runner, nargs, args, expect): + @click.command() + @click.option("-p", "--point", nargs=nargs, type=int) + def cli(point): + pass + + result = runner.invoke(cli, args) + assert result.exit_code == 2 + assert f"Error: {expect}" in result.output + + +@pytest.mark.parametrize( + ("args", "expect"), + [ + (["-ab"], (True, True, None)), + (["-ba"], (True, True, None)), + (["-abo", "value"], (True, True, "value")), + (["-abovalue"], (True, True, "value")), + (["-aovalue"], (True, False, "value")), + ], +) +def test_bundled_short_flags(runner, args, expect): + @click.command() + @click.option("-a", is_flag=True) + @click.option("-b", is_flag=True) + @click.option("-o") + def cli(a, b, o): + return a, b, o + + result = runner.invoke(cli, args, standalone_mode=False, catch_exceptions=False) + assert result.return_value == expect + + def test_multiple_required(runner): @click.command() @click.option("-m", "--message", multiple=True, required=True) From 7e2545f4d99bf0233020e6e1c04d2f4e2f46b259 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:59:42 -0800 Subject: [PATCH 04/18] Fix name clash after normalization such that name becomes unreachable --- CHANGES.md | 5 +++ src/click/core.py | 31 +++++++++++++--- tests/test_options.py | 84 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2694eefd0..fbe78fb2f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,11 @@ Unreleased - `Context.protected_args` always returns an empty list. The subcommand name and its arguments are in `Context.args`. +- Option names that only become equal after `token_normalize_func`, such as + `-v` and `-V` with a lower-casing function, raise a `TypeError` when parsing + instead of one silently making the other unreachable. This includes the on + and off names of a boolean flag, such as `-s/-S`. + - A parameter name that is not a valid Python identifier, or that is a Python keyword, is deprecated and raises `TypeError` in Click 9.0. {pr}`3866` - An {class}`Option` name written as a Python identifier is deprecated when it diff --git a/src/click/core.py b/src/click/core.py index 12e9d3b0c..211e34fc4 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -1401,17 +1401,40 @@ def normalize(name: str) -> str: # Normalized secondary names, for easier comparison during parsing. secondary_opts: set[str] = set() arg_params: list[Argument] = [] + # Normalized name to the option, declared spelling, and whether it's a + # secondary name, to detect spellings that only collide after normalizing. + claimed: dict[str, tuple[Option, str, bool]] = {} for param in params: if isinstance(param, Option): - names = list(param.opts) + names = [(n, False) for n in param.opts] if param.is_bool_flag and param.secondary_opts: - names.extend(param.secondary_opts) + names.extend((n, True) for n in param.secondary_opts) secondary_opts.update(normalize(n) for n in param.secondary_opts) - for name in names: - name = normalize(name) + for original, is_secondary in names: + name = normalize(original) + + if name in claimed: + other, other_original, other_is_secondary = claimed[name] + + # An identical spelling is a duplicate declaration, which + # get_params warns about, and the last one keeps winning. + if original != other_original and ( + other is not param or other_is_secondary != is_secondary + ): + raise TypeError( + _( + "The option names {first!r} and {second!r} both" + " normalize to {name!r}. Give them names that" + " stay distinct after 'token_normalize_func'." + ).format( + first=other_original, second=original, name=name + ) + ) + + claimed[name] = (param, original, is_secondary) prefix, value = _split_opt(name) opt_prefixes.add(prefix[0]) diff --git a/tests/test_options.py b/tests/test_options.py index ce5c3e14e..d088b4bf2 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -3784,6 +3784,90 @@ def cli(xyz): runner.invoke(cli, []) +@pytest.mark.parametrize( + ("params", "first", "second"), + [ + pytest.param( + [click.Option(["-s/-S"], default=None)], "-s", "-S", id="secondary" + ), + pytest.param( + [ + click.Option(["-v", "verbose"], is_flag=True), + click.Option(["-V", "version"], is_flag=True), + ], + "-v", + "-V", + id="separate options", + ), + pytest.param( + [ + click.Option(["-V", "version"], is_flag=True), + click.Option(["-v", "verbose"], is_flag=True), + ], + "-V", + "-v", + id="separate options reversed", + ), + ], +) +def test_option_names_collide_after_normalization(params, first, second): + """Names that only become equal after normalization would silently make one + of them unreachable. + """ + cli = click.Command( + "cli", params=params, context_settings={"token_normalize_func": str.lower} + ) + + with pytest.raises(TypeError, match=f"'{first}' and '{second}' both normalize"): + cli.make_context("cli", []) + + +@pytest.mark.parametrize("args", [["--Foo", "1"], ["--foo", "1"], ["--FOO", "1"]]) +def test_option_names_of_same_option_normalize_together(args): + """Spellings of the same option that normalize to one name are harmless.""" + cli = click.Command( + "cli", + params=[click.Option(["--Foo", "--foo"])], + context_settings={"token_normalize_func": str.lower}, + ) + assert cli.make_context("cli", args).params == {"foo": "1"} + + +def test_duplicate_option_name_with_normalization_only_warns(): + """An identical spelling declared twice keeps warning instead of raising, + and the parser still uses the last declaration. + """ + cli = click.Command( + "cli", + params=[click.Option(["--xyz"]), click.Option(["--xyz"])], + context_settings={"token_normalize_func": str.lower}, + ) + + with pytest.warns(UserWarning, match="used more than once"): + ctx = cli.make_context("cli", ["--XYZ", "value"]) + + assert ctx.params == {"xyz": "value"} + + +@pytest.mark.parametrize( + ("args", "expect"), + [ + (["-v"], {"verbose": True, "version": False}), + (["-V"], {"verbose": False, "version": True}), + ], +) +def test_option_names_differing_in_case_without_normalization(args, expect): + """Without a normalize function, names that differ only in case are distinct.""" + cli = click.Command( + "cli", + params=[ + click.Option(["-v", "verbose"], is_flag=True), + click.Option(["-V", "version"], is_flag=True), + ], + ) + assert cli.make_context("cli", args).params == expect + + def test_argument_sharing_param_name_warning(runner): """An argument sharing its storage name with an option makes both silently overwrite each other's value, which triggers a warning. From 23c6b93077936e08d82f69a65d78deb274e1d6b1 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Wed, 18 Nov 2026 23:18:52 -0800 Subject: [PATCH 05/18] Remove parser deprecations. Make split_arg_string public. --- CHANGES.md | 6 ++++-- docs/api.md | 4 ++++ docs/shell-completion.md | 4 ++-- src/click/__init__.py | 1 + src/click/parser.py | 25 ------------------------- src/click/shell_completion.py | 3 +++ tests/test_deprecations.py | 7 +------ 7 files changed, 15 insertions(+), 35 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index fbe78fb2f..ff83e64b3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,4 @@ -## Version 8.6.0 +## Version 9.0.0 Unreleased @@ -6,7 +6,9 @@ Unreleased parses arguments directly. {issue}`2205` - `OptionParser` is removed from `click` and `click.parser`, along with - `click.parser.Option`, `Argument`, `ParsingState`, and `normalize_opt`. + `click.parser.Option`, `Argument`, `ParsingState`, `normalize_opt`, and + `split_opt`. `split_arg_string` is available as + {func}`click.split_arg_string`. Use `optparse` from the standard library if you need the old parser. - `Command.make_parser` and `Parameter.add_to_parser` are removed. - `Context.protected_args` always returns an empty list. The subcommand diff --git a/docs/api.md b/docs/api.md index 4ba578908..1bb8f244a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -338,6 +338,10 @@ customizing Click's shell completion system. ``` +```{eval-rst} +.. autofunction:: click.split_arg_string +``` + (testing)= ## Testing diff --git a/docs/shell-completion.md b/docs/shell-completion.md index 2cc3c843d..b33d3a427 100644 --- a/docs/shell-completion.md +++ b/docs/shell-completion.md @@ -238,13 +238,13 @@ must return a `(args, incomplete)` tuple. ```python import os -from click.parser import split_arg_string +import click class MyshComplete(ShellComplete): ... def get_completion_args(self): - args = split_arg_string(os.environ["COMP_WORDS"]) + args = click.split_arg_string(os.environ["COMP_WORDS"]) if os.environ["COMP_PARTIAL"] == "1": incomplete = args.pop() diff --git a/src/click/__init__.py b/src/click/__init__.py index 0a62a4f3d..25079ff41 100644 --- a/src/click/__init__.py +++ b/src/click/__init__.py @@ -40,6 +40,7 @@ from .formatting import HelpFormatter as HelpFormatter from .formatting import wrap_text as wrap_text from .globals import get_current_context as get_current_context +from .shell_completion import split_arg_string as split_arg_string from .termui import clear as clear from .termui import confirm as confirm from .termui import echo_via_pager as echo_via_pager diff --git a/src/click/parser.py b/src/click/parser.py index fcfd8c77d..9cf5a7e00 100644 --- a/src/click/parser.py +++ b/src/click/parser.py @@ -9,28 +9,3 @@ def _split_opt(opt: str) -> tuple[str, str]: if opt[1:2] == first: return opt[:2], opt[2:] return first, opt[1:] - - -def __getattr__(name: str) -> object: - import warnings - - if name == "split_opt": - warnings.warn( - "'parser.split_opt' is deprecated and will be removed in Click 9.0.", - DeprecationWarning, - stacklevel=2, - ) - return _split_opt - - if name == "split_arg_string": - from .shell_completion import split_arg_string - - warnings.warn( - "Importing 'parser.split_arg_string' is deprecated, it will only be" - " available in 'shell_completion' in Click 9.0.", - DeprecationWarning, - stacklevel=2, - ) - return split_arg_string - - raise AttributeError(name) diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py index 4720bef01..7cc089a9b 100644 --- a/src/click/shell_completion.py +++ b/src/click/shell_completion.py @@ -610,6 +610,9 @@ def split_arg_string(string: str) -> list[str]: :param string: String to split. + .. versionchanged:: 9.0 + Available as ``click.split_arg_string``. + .. versionchanged:: 8.2 Moved to ``shell_completion`` from ``parser``. """ diff --git a/tests/test_deprecations.py b/tests/test_deprecations.py index 72468d8ec..c46a552fc 100644 --- a/tests/test_deprecations.py +++ b/tests/test_deprecations.py @@ -5,8 +5,6 @@ import click import click.core -import click.parser -import click.shell_completion import click.utils @@ -23,9 +21,6 @@ (click, "MultiCommand", click.core._MultiCommand), (click.core, "BaseCommand", click.core._BaseCommand), (click.core, "MultiCommand", click.core._MultiCommand), - # Remaining `click.parser` helpers. - (click.parser, "split_opt", click.parser._split_opt), - (click.parser, "split_arg_string", click.shell_completion.split_arg_string), # Deprecated `click.utils` utilities. (click.utils, "LazyFile", click.utils._LazyFile), (click.utils, "KeepOpenFile", click.utils._KeepOpenFile), @@ -46,7 +41,7 @@ def test_attr_deprecated(module, name, target): @pytest.mark.parametrize( "module", - [click, click.core, click.parser, click.utils], + [click, click.core, click.utils], ids=lambda m: m.__name__, ) def test_unknown_attribute_raises(module): From 73686c28ffb3e9b03fd945137052fea924e69770 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Wed, 18 Nov 2026 23:25:24 -0800 Subject: [PATCH 06/18] Upgrade to 3.11 plus. --- pyproject.toml | 2 +- uv.lock | 312 +++---------------------------------------------- 2 files changed, 17 insertions(+), 297 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 530060e3c..bdb6c8e20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ classifiers = [ "Programming Language :: Python", "Typing :: Typed", ] -requires-python = ">=3.10" +requires-python = ">=3.11" [project.urls] Donate = "https://palletsprojects.com/donate" diff --git a/uv.lock b/uv.lock index 2b8673c0e..54eda98dd 100644 --- a/uv.lock +++ b/uv.lock @@ -1,10 +1,9 @@ version = 1 revision = 5 -requires-python = ">=3.10" +requires-python = ">=3.11" resolution-markers = [ "python_full_version >= '3.12'", - "python_full_version == '3.11.*'", - "python_full_version < '3.11'", + "python_full_version < '3.12'", ] [[package]] @@ -21,7 +20,6 @@ name = "anyio" version = "4.13.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "exceptiongroup", marker = "python_full_version < '3.11'" }, { name = "idna" }, { name = "typing-extensions", marker = "python_full_version < '3.13'" }, ] @@ -72,22 +70,6 @@ version = "3.4.7" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/e7/a1/67fe25fac3c7642725500a3f6cfe5821ad557c3abb11c9d20d12c7008d3e/charset_normalizer-3.4.7.tar.gz", hash = "sha256:ae89db9e5f98a11a4bf50407d4363e7b09b31e55bc117b4f7d80aab97ba009e5", size = 144271, upload-time = "2026-04-02T09:28:39.342Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/26/08/0f303cb0b529e456bb116f2d50565a482694fbb94340bf56d44677e7ed03/charset_normalizer-3.4.7-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:cdd68a1fb318e290a2077696b7eb7a21a49163c455979c639bf5a5dcdc46617d", size = 315182, upload-time = "2026-04-02T09:25:40.673Z" }, - { url = "https://files.pythonhosted.org/packages/24/47/b192933e94b546f1b1fe4df9cc1f84fcdbf2359f8d1081d46dd029b50207/charset_normalizer-3.4.7-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:e17b8d5d6a8c47c85e68ca8379def1303fd360c3e22093a807cd34a71cd082b8", size = 209329, upload-time = "2026-04-02T09:25:42.354Z" }, - { url = "https://files.pythonhosted.org/packages/c2/b4/01fa81c5ca6141024d89a8fc15968002b71da7f825dd14113207113fabbd/charset_normalizer-3.4.7-cp310-cp310-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:511ef87c8aec0783e08ac18565a16d435372bc1ac25a91e6ac7f5ef2b0bff790", size = 231230, upload-time = "2026-04-02T09:25:44.281Z" }, - { url = "https://files.pythonhosted.org/packages/20/f7/7b991776844dfa058017e600e6e55ff01984a063290ca5622c0b63162f68/charset_normalizer-3.4.7-cp310-cp310-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:007d05ec7321d12a40227aae9e2bc6dca73f3cb21058999a1df9e193555a9dcc", size = 225890, upload-time = "2026-04-02T09:25:45.475Z" }, - { url = "https://files.pythonhosted.org/packages/20/e7/bed0024a0f4ab0c8a9c64d4445f39b30c99bd1acd228291959e3de664247/charset_normalizer-3.4.7-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:cf29836da5119f3c8a8a70667b0ef5fdca3bb12f80fd06487cfa575b3909b393", size = 216930, upload-time = "2026-04-02T09:25:46.58Z" }, - { url = "https://files.pythonhosted.org/packages/e2/ab/b18f0ab31cdd7b3ddb8bb76c4a414aeb8160c9810fdf1bc62f269a539d87/charset_normalizer-3.4.7-cp310-cp310-manylinux_2_31_armv7l.whl", hash = "sha256:12d8baf840cc7889b37c7c770f478adea7adce3dcb3944d02ec87508e2dcf153", size = 202109, upload-time = "2026-04-02T09:25:48.031Z" }, - { url = "https://files.pythonhosted.org/packages/82/e5/7e9440768a06dfb3075936490cb82dbf0ee20a133bf0dd8551fa096914ec/charset_normalizer-3.4.7-cp310-cp310-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:d560742f3c0d62afaccf9f41fe485ed69bd7661a241f86a3ef0f0fb8b1a397af", size = 214684, upload-time = "2026-04-02T09:25:49.245Z" }, - { url = "https://files.pythonhosted.org/packages/71/94/8c61d8da9f062fdf457c80acfa25060ec22bf1d34bbeaca4350f13bcfd07/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:b14b2d9dac08e28bb8046a1a0434b1750eb221c8f5b87a68f4fa11a6f97b5e34", size = 212785, upload-time = "2026-04-02T09:25:50.671Z" }, - { url = "https://files.pythonhosted.org/packages/66/cd/6e9889c648e72c0ab2e5967528bb83508f354d706637bc7097190c874e13/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_armv7l.whl", hash = "sha256:bc17a677b21b3502a21f66a8cc64f5bfad4df8a0b8434d661666f8ce90ac3af1", size = 203055, upload-time = "2026-04-02T09:25:51.802Z" }, - { url = "https://files.pythonhosted.org/packages/92/2e/7a951d6a08aefb7eb8e1b54cdfb580b1365afdd9dd484dc4bee9e5d8f258/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_ppc64le.whl", hash = "sha256:750e02e074872a3fad7f233b47734166440af3cdea0add3e95163110816d6752", size = 232502, upload-time = "2026-04-02T09:25:53.388Z" }, - { url = "https://files.pythonhosted.org/packages/58/d5/abcf2d83bf8e0a1286df55cd0dc1d49af0da4282aa77e986df343e7de124/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_riscv64.whl", hash = "sha256:4e5163c14bffd570ef2affbfdd77bba66383890797df43dc8b4cc7d6f500bf53", size = 214295, upload-time = "2026-04-02T09:25:54.765Z" }, - { url = "https://files.pythonhosted.org/packages/47/3a/7d4cd7ed54be99973a0dc176032cba5cb1f258082c31fa6df35cff46acfc/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_s390x.whl", hash = "sha256:6ed74185b2db44f41ef35fd1617c5888e59792da9bbc9190d6c7300617182616", size = 227145, upload-time = "2026-04-02T09:25:55.904Z" }, - { url = "https://files.pythonhosted.org/packages/1d/98/3a45bf8247889cf28262ebd3d0872edff11565b2a1e3064ccb132db3fbb0/charset_normalizer-3.4.7-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:94e1885b270625a9a828c9793b4d52a64445299baa1fea5a173bf1d3dd9a1a5a", size = 218884, upload-time = "2026-04-02T09:25:57.074Z" }, - { url = "https://files.pythonhosted.org/packages/ad/80/2e8b7f8915ed5c9ef13aa828d82738e33888c485b65ebf744d615040c7ea/charset_normalizer-3.4.7-cp310-cp310-win32.whl", hash = "sha256:6785f414ae0f3c733c437e0f3929197934f526d19dfaa75e18fdb4f94c6fb374", size = 148343, upload-time = "2026-04-02T09:25:58.199Z" }, - { url = "https://files.pythonhosted.org/packages/35/1b/3b8c8c77184af465ee9ad88b5aea46ea6b2e1f7b9dc9502891e37af21e30/charset_normalizer-3.4.7-cp310-cp310-win_amd64.whl", hash = "sha256:6696b7688f54f5af4462118f0bfa7c1621eeb87154f77fa04b9295ce7a8f2943", size = 159174, upload-time = "2026-04-02T09:25:59.322Z" }, - { url = "https://files.pythonhosted.org/packages/be/c1/feb40dca40dbb21e0a908801782d9288c64fc8d8e562c2098e9994c8c21b/charset_normalizer-3.4.7-cp310-cp310-win_arm64.whl", hash = "sha256:66671f93accb62ed07da56613636f3641f1a12c13046ce91ffc923721f23c008", size = 147805, upload-time = "2026-04-02T09:26:00.756Z" }, { url = "https://files.pythonhosted.org/packages/c2/d7/b5b7020a0565c2e9fa8c09f4b5fa6232feb326b8c20081ccded47ea368fd/charset_normalizer-3.4.7-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:7641bb8895e77f921102f72833904dcd9901df5d6d72a2ab8f31d04b7e51e4e7", size = 309705, upload-time = "2026-04-02T09:26:02.191Z" }, { url = "https://files.pythonhosted.org/packages/5a/53/58c29116c340e5456724ecd2fff4196d236b98f3da97b404bc5e51ac3493/charset_normalizer-3.4.7-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:202389074300232baeb53ae2569a60901f7efadd4245cf3a3bf0617d60b439d7", size = 206419, upload-time = "2026-04-02T09:26:03.583Z" }, { url = "https://files.pythonhosted.org/packages/b2/02/e8146dc6591a37a00e5144c63f29fb7c97a734ea8a111190783c0e60ab63/charset_normalizer-3.4.7-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:30b8d1d8c52a48c2c5690e152c169b673487a2a58de1ec7393196753063fcd5e", size = 227901, upload-time = "2026-04-02T09:26:04.738Z" }, @@ -184,18 +166,15 @@ dev = [ { name = "tox-uv" }, ] docs = [ - { name = "myst-parser", version = "4.0.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "myst-parser", version = "5.0.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, + { name = "myst-parser" }, { name = "pallets-sphinx-themes" }, - { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" }, + { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, { name = "sphinx", version = "9.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" }, { name = "sphinx-tabs" }, { name = "sphinxcontrib-log-cabinet" }, ] docs-auto = [ - { name = "sphinx-autobuild", version = "2024.10.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "sphinx-autobuild", version = "2025.8.25", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, + { name = "sphinx-autobuild" }, ] gha-update = [ { name = "gha-update", marker = "python_full_version >= '3.12'" }, @@ -269,43 +248,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/33/6b/e0547afaf41bf2c42e52430072fa5658766e3d65bd4b03a563d1b6336f57/distlib-0.4.0-py2.py3-none-any.whl", hash = "sha256:9659f7d87e46584a30b5780e43ac7a2143098441670ff0a49d5f9034c54a6c16", size = 469047, upload-time = "2025-07-17T16:51:58.613Z" }, ] -[[package]] -name = "docutils" -version = "0.21.2" -source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version < '3.11'", -] -sdist = { url = "https://files.pythonhosted.org/packages/ae/ed/aefcc8cd0ba62a0560c3c18c33925362d46c6075480bfa4df87b28e169a9/docutils-0.21.2.tar.gz", hash = "sha256:3a6b18732edf182daa3cd12775bbb338cf5691468f91eeeb109deff6ebfa986f", size = 2204444, upload-time = "2024-04-23T18:57:18.24Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/8f/d7/9322c609343d929e75e7e5e6255e614fcc67572cfd083959cdef3b7aad79/docutils-0.21.2-py3-none-any.whl", hash = "sha256:dafca5b9e384f0e419294eb4d2ff9fa826435bf15f15b7bd45723e8ad76811b2", size = 587408, upload-time = "2024-04-23T18:57:14.835Z" }, -] - [[package]] name = "docutils" version = "0.22.4" source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version >= '3.12'", - "python_full_version == '3.11.*'", -] sdist = { url = "https://files.pythonhosted.org/packages/ae/b6/03bb70946330e88ffec97aefd3ea75ba575cb2e762061e0e62a213befee8/docutils-0.22.4.tar.gz", hash = "sha256:4db53b1fde9abecbb74d91230d32ab626d94f6badfc575d6db9194a49df29968", size = 2291750, upload-time = "2025-12-18T19:00:26.443Z" } wheels = [ { url = "https://files.pythonhosted.org/packages/02/10/5da547df7a391dcde17f59520a231527b8571e6f46fc8efb02ccb370ab12/docutils-0.22.4-py3-none-any.whl", hash = "sha256:d0013f540772d1420576855455d050a2180186c91c15779301ac2ccb3eeb68de", size = 633196, upload-time = "2025-12-18T19:00:18.077Z" }, ] -[[package]] -name = "exceptiongroup" -version = "1.3.1" -source = { registry = "https://pypi.org/simple" } -dependencies = [ - { name = "typing-extensions" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/50/79/66800aadf48771f6b62f7eb014e352e5d06856655206165d775e675a02c9/exceptiongroup-1.3.1.tar.gz", hash = "sha256:8b412432c6055b0b7d14c310000ae93352ed6754f70fa8f7c34141f91c4e3219", size = 30371, upload-time = "2025-11-21T23:01:54.787Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/8a/0e/97c33bf5009bdbac74fd2beace167cab3f978feb69cc36f1ef79360d6c4e/exceptiongroup-1.3.1-py3-none-any.whl", hash = "sha256:a7a39a3bd276781e98394987d3a5701d0c4edffb633bb7a5144577f82c773598", size = 16740, upload-time = "2025-11-21T23:01:53.443Z" }, -] - [[package]] name = "execnet" version = "2.1.2" @@ -428,18 +379,6 @@ version = "0.8.1" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/56/9c/b4b0c54d84da4a94b37bd44151e46d5e583c9534c7e02250b961b1b6d8a8/librt-0.8.1.tar.gz", hash = "sha256:be46a14693955b3bd96014ccbdb8339ee8c9346fbe11c1b78901b55125f14c73", size = 177471, upload-time = "2026-02-17T16:13:06.101Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/7c/5f/63f5fa395c7a8a93558c0904ba8f1c8d1b997ca6a3de61bc7659970d66bf/librt-0.8.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:81fd938344fecb9373ba1b155968c8a329491d2ce38e7ddb76f30ffb938f12dc", size = 65697, upload-time = "2026-02-17T16:11:06.903Z" }, - { url = "https://files.pythonhosted.org/packages/ff/e0/0472cf37267b5920eff2f292ccfaede1886288ce35b7f3203d8de00abfe6/librt-0.8.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:5db05697c82b3a2ec53f6e72b2ed373132b0c2e05135f0696784e97d7f5d48e7", size = 68376, upload-time = "2026-02-17T16:11:08.395Z" }, - { url = "https://files.pythonhosted.org/packages/c8/be/8bd1359fdcd27ab897cd5963294fa4a7c83b20a8564678e4fd12157e56a5/librt-0.8.1-cp310-cp310-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:d56bc4011975f7460bea7b33e1ff425d2f1adf419935ff6707273c77f8a4ada6", size = 197084, upload-time = "2026-02-17T16:11:09.774Z" }, - { url = "https://files.pythonhosted.org/packages/e2/fe/163e33fdd091d0c2b102f8a60cc0a61fd730ad44e32617cd161e7cd67a01/librt-0.8.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5cdc0f588ff4b663ea96c26d2a230c525c6fc62b28314edaaaca8ed5af931ad0", size = 207337, upload-time = "2026-02-17T16:11:11.311Z" }, - { url = "https://files.pythonhosted.org/packages/01/99/f85130582f05dcf0c8902f3d629270231d2f4afdfc567f8305a952ac7f14/librt-0.8.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:97c2b54ff6717a7a563b72627990bec60d8029df17df423f0ed37d56a17a176b", size = 219980, upload-time = "2026-02-17T16:11:12.499Z" }, - { url = "https://files.pythonhosted.org/packages/6f/54/cb5e4d03659e043a26c74e08206412ac9a3742f0477d96f9761a55313b5f/librt-0.8.1-cp310-cp310-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:8f1125e6bbf2f1657d9a2f3ccc4a2c9b0c8b176965bb565dd4d86be67eddb4b6", size = 212921, upload-time = "2026-02-17T16:11:14.484Z" }, - { url = "https://files.pythonhosted.org/packages/b1/81/a3a01e4240579c30f3487f6fed01eb4bc8ef0616da5b4ebac27ca19775f3/librt-0.8.1-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:8f4bb453f408137d7581be309b2fbc6868a80e7ef60c88e689078ee3a296ae71", size = 221381, upload-time = "2026-02-17T16:11:17.459Z" }, - { url = "https://files.pythonhosted.org/packages/08/b0/fc2d54b4b1c6fb81e77288ff31ff25a2c1e62eaef4424a984f228839717b/librt-0.8.1-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:c336d61d2fe74a3195edc1646d53ff1cddd3a9600b09fa6ab75e5514ba4862a7", size = 216714, upload-time = "2026-02-17T16:11:19.197Z" }, - { url = "https://files.pythonhosted.org/packages/96/96/85daa73ffbd87e1fb287d7af6553ada66bf25a2a6b0de4764344a05469f6/librt-0.8.1-cp310-cp310-musllinux_1_2_riscv64.whl", hash = "sha256:eb5656019db7c4deacf0c1a55a898c5bb8f989be904597fcb5232a2f4828fa05", size = 214777, upload-time = "2026-02-17T16:11:20.443Z" }, - { url = "https://files.pythonhosted.org/packages/12/9c/c3aa7a2360383f4bf4f04d98195f2739a579128720c603f4807f006a4225/librt-0.8.1-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:c25d9e338d5bed46c1632f851babf3d13c78f49a225462017cf5e11e845c5891", size = 237398, upload-time = "2026-02-17T16:11:22.083Z" }, - { url = "https://files.pythonhosted.org/packages/61/19/d350ea89e5274665185dabc4bbb9c3536c3411f862881d316c8b8e00eb66/librt-0.8.1-cp310-cp310-win32.whl", hash = "sha256:aaab0e307e344cb28d800957ef3ec16605146ef0e59e059a60a176d19543d1b7", size = 54285, upload-time = "2026-02-17T16:11:23.27Z" }, - { url = "https://files.pythonhosted.org/packages/4f/d6/45d587d3d41c112e9543a0093d883eb57a24a03e41561c127818aa2a6bcc/librt-0.8.1-cp310-cp310-win_amd64.whl", hash = "sha256:56e04c14b696300d47b3bc5f1d10a00e86ae978886d0cee14e5714fafb5df5d2", size = 61352, upload-time = "2026-02-17T16:11:24.207Z" }, { url = "https://files.pythonhosted.org/packages/1d/01/0e748af5e4fee180cf7cd12bd12b0513ad23b045dccb2a83191bde82d168/librt-0.8.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:681dc2451d6d846794a828c16c22dc452d924e9f700a485b7ecb887a30aad1fd", size = 65315, upload-time = "2026-02-17T16:11:25.152Z" }, { url = "https://files.pythonhosted.org/packages/9d/4d/7184806efda571887c798d573ca4134c80ac8642dcdd32f12c31b939c595/librt-0.8.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:a3b4350b13cc0e6f5bec8fa7caf29a8fb8cdc051a3bae45cfbfd7ce64f009965", size = 68021, upload-time = "2026-02-17T16:11:26.129Z" }, { url = "https://files.pythonhosted.org/packages/ae/88/c3c52d2a5d5101f28d3dc89298444626e7874aa904eed498464c2af17627/librt-0.8.1-cp311-cp311-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:ac1e7817fd0ed3d14fd7c5df91daed84c48e4c2a11ee99c0547f9f62fdae13da", size = 194500, upload-time = "2026-02-17T16:11:27.177Z" }, @@ -507,29 +446,10 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b2/c8/d148e041732d631fc76036f8b30fae4e77b027a1e95b7a84bb522481a940/librt-0.8.1-cp314-cp314t-win_arm64.whl", hash = "sha256:bf512a71a23504ed08103a13c941f763db13fb11177beb3d9244c98c29fb4a61", size = 48755, upload-time = "2026-02-17T16:12:47.943Z" }, ] -[[package]] -name = "markdown-it-py" -version = "3.0.0" -source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version < '3.11'", -] -dependencies = [ - { name = "mdurl" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/38/71/3b932df36c1a044d397a1f92d1cf91ee0a503d91e470cbd670aa66b07ed0/markdown-it-py-3.0.0.tar.gz", hash = "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb", size = 74596, upload-time = "2023-06-03T06:41:14.443Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/42/d7/1ec15b46af6af88f19b8e5ffea08fa375d433c998b8a7639e76935c14f1f/markdown_it_py-3.0.0-py3-none-any.whl", hash = "sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1", size = 87528, upload-time = "2023-06-03T06:41:11.019Z" }, -] - [[package]] name = "markdown-it-py" version = "4.0.0" source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version >= '3.12'", - "python_full_version == '3.11.*'", -] dependencies = [ { name = "mdurl" }, ] @@ -544,17 +464,6 @@ version = "3.0.3" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/7e/99/7690b6d4034fffd95959cbe0c02de8deb3098cc577c67bb6a24fe5d7caa7/markupsafe-3.0.3.tar.gz", hash = "sha256:722695808f4b6457b320fdc131280796bdceb04ab50fe1795cd540799ebe1698", size = 80313, upload-time = "2025-09-27T18:37:40.426Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/e8/4b/3541d44f3937ba468b75da9eebcae497dcf67adb65caa16760b0a6807ebb/markupsafe-3.0.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:2f981d352f04553a7171b8e44369f2af4055f888dfb147d55e42d29e29e74559", size = 11631, upload-time = "2025-09-27T18:36:05.558Z" }, - { url = "https://files.pythonhosted.org/packages/98/1b/fbd8eed11021cabd9226c37342fa6ca4e8a98d8188a8d9b66740494960e4/markupsafe-3.0.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:e1c1493fb6e50ab01d20a22826e57520f1284df32f2d8601fdd90b6304601419", size = 12057, upload-time = "2025-09-27T18:36:07.165Z" }, - { url = "https://files.pythonhosted.org/packages/40/01/e560d658dc0bb8ab762670ece35281dec7b6c1b33f5fbc09ebb57a185519/markupsafe-3.0.3-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1ba88449deb3de88bd40044603fafffb7bc2b055d626a330323a9ed736661695", size = 22050, upload-time = "2025-09-27T18:36:08.005Z" }, - { url = "https://files.pythonhosted.org/packages/af/cd/ce6e848bbf2c32314c9b237839119c5a564a59725b53157c856e90937b7a/markupsafe-3.0.3-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:f42d0984e947b8adf7dd6dde396e720934d12c506ce84eea8476409563607591", size = 20681, upload-time = "2025-09-27T18:36:08.881Z" }, - { url = "https://files.pythonhosted.org/packages/c9/2a/b5c12c809f1c3045c4d580b035a743d12fcde53cf685dbc44660826308da/markupsafe-3.0.3-cp310-cp310-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c0c0b3ade1c0b13b936d7970b1d37a57acde9199dc2aecc4c336773e1d86049c", size = 20705, upload-time = "2025-09-27T18:36:10.131Z" }, - { url = "https://files.pythonhosted.org/packages/cf/e3/9427a68c82728d0a88c50f890d0fc072a1484de2f3ac1ad0bfc1a7214fd5/markupsafe-3.0.3-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:0303439a41979d9e74d18ff5e2dd8c43ed6c6001fd40e5bf2e43f7bd9bbc523f", size = 21524, upload-time = "2025-09-27T18:36:11.324Z" }, - { url = "https://files.pythonhosted.org/packages/bc/36/23578f29e9e582a4d0278e009b38081dbe363c5e7165113fad546918a232/markupsafe-3.0.3-cp310-cp310-musllinux_1_2_riscv64.whl", hash = "sha256:d2ee202e79d8ed691ceebae8e0486bd9a2cd4794cec4824e1c99b6f5009502f6", size = 20282, upload-time = "2025-09-27T18:36:12.573Z" }, - { url = "https://files.pythonhosted.org/packages/56/21/dca11354e756ebd03e036bd8ad58d6d7168c80ce1fe5e75218e4945cbab7/markupsafe-3.0.3-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:177b5253b2834fe3678cb4a5f0059808258584c559193998be2601324fdeafb1", size = 20745, upload-time = "2025-09-27T18:36:13.504Z" }, - { url = "https://files.pythonhosted.org/packages/87/99/faba9369a7ad6e4d10b6a5fbf71fa2a188fe4a593b15f0963b73859a1bbd/markupsafe-3.0.3-cp310-cp310-win32.whl", hash = "sha256:2a15a08b17dd94c53a1da0438822d70ebcd13f8c3a95abe3a9ef9f11a94830aa", size = 14571, upload-time = "2025-09-27T18:36:14.779Z" }, - { url = "https://files.pythonhosted.org/packages/d6/25/55dc3ab959917602c96985cb1253efaa4ff42f71194bddeb61eb7278b8be/markupsafe-3.0.3-cp310-cp310-win_amd64.whl", hash = "sha256:c4ffb7ebf07cfe8931028e3e4c85f0357459a3f9f9490886198848f4fa002ec8", size = 15056, upload-time = "2025-09-27T18:36:16.125Z" }, - { url = "https://files.pythonhosted.org/packages/d0/9e/0a02226640c255d1da0b8d12e24ac2aa6734da68bff14c05dd53b94a0fc3/markupsafe-3.0.3-cp310-cp310-win_arm64.whl", hash = "sha256:e2103a929dfa2fcaf9bb4e7c091983a49c9ac3b19c9061b6d5427dd7d14d81a1", size = 13932, upload-time = "2025-09-27T18:36:17.311Z" }, { url = "https://files.pythonhosted.org/packages/08/db/fefacb2136439fc8dd20e797950e749aa1f4997ed584c62cfb8ef7c2be0e/markupsafe-3.0.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:1cc7ea17a6824959616c525620e387f6dd30fec8cb44f649e31712db02123dad", size = 11631, upload-time = "2025-09-27T18:36:18.185Z" }, { url = "https://files.pythonhosted.org/packages/e1/2e/5898933336b61975ce9dc04decbc0a7f2fee78c30353c5efba7f2d6ff27a/markupsafe-3.0.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4bd4cd07944443f5a265608cc6aab442e4f74dff8088b0dfc8238647b8f6ae9a", size = 12058, upload-time = "2025-09-27T18:36:19.444Z" }, { url = "https://files.pythonhosted.org/packages/1d/09/adf2df3699d87d1d8184038df46a9c80d78c0148492323f4693df54e17bb/markupsafe-3.0.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6b5420a1d9450023228968e7e6a9ce57f65d148ab56d2313fcd589eee96a7a50", size = 24287, upload-time = "2025-09-27T18:36:20.768Z" }, @@ -628,8 +537,7 @@ name = "mdit-py-plugins" version = "0.5.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "markdown-it-py", version = "3.0.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "markdown-it-py", version = "4.0.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, + { name = "markdown-it-py" }, ] sdist = { url = "https://files.pythonhosted.org/packages/b2/fd/a756d36c0bfba5f6e39a1cdbdbfdd448dc02692467d83816dff4592a1ebc/mdit_py_plugins-0.5.0.tar.gz", hash = "sha256:f4918cb50119f50446560513a8e311d574ff6aaed72606ddae6d35716fe809c6", size = 44655, upload-time = "2025-08-11T07:25:49.083Z" } wheels = [ @@ -653,18 +561,10 @@ dependencies = [ { name = "librt", marker = "platform_python_implementation != 'PyPy'" }, { name = "mypy-extensions" }, { name = "pathspec" }, - { name = "tomli", marker = "python_full_version < '3.11'" }, { name = "typing-extensions" }, ] sdist = { url = "https://files.pythonhosted.org/packages/f8/5c/b0089fe7fef0a994ae5ee07029ced0526082c6cfaaa4c10d40a10e33b097/mypy-1.20.0.tar.gz", hash = "sha256:eb96c84efcc33f0b5e0e04beacf00129dd963b67226b01c00b9dfc8affb464c3", size = 3815028, upload-time = "2026-03-31T16:55:14.959Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/4d/a2/a965c8c3fcd4fa8b84ba0d46606181b0d0a1d50f274c67877f3e9ed4882c/mypy-1.20.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d99f515f95fd03a90875fdb2cca12ff074aa04490db4d190905851bdf8a549a8", size = 14430138, upload-time = "2026-03-31T16:52:37.843Z" }, - { url = "https://files.pythonhosted.org/packages/53/6e/043477501deeb8eabbab7f1a2f6cac62cfb631806dc1d6862a04a7f5011b/mypy-1.20.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:bd0212976dc57a5bfeede7c219e7cd66568a32c05c9129686dd487c059c1b88a", size = 13311282, upload-time = "2026-03-31T16:55:11.021Z" }, - { url = "https://files.pythonhosted.org/packages/65/aa/bd89b247b83128197a214f29f0632ff3c14f54d4cd70d144d157bd7d7d6e/mypy-1.20.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f8426d4d75d68714abc17a4292d922f6ba2cfb984b72c2278c437f6dae797865", size = 13750889, upload-time = "2026-03-31T16:52:02.909Z" }, - { url = "https://files.pythonhosted.org/packages/fa/9d/2860be7355c45247ccc0be1501c91176318964c2a137bd4743f58ce6200e/mypy-1.20.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:02cca0761c75b42a20a2757ae58713276605eb29a08dd8a6e092aa347c4115ca", size = 14619788, upload-time = "2026-03-31T16:50:48.928Z" }, - { url = "https://files.pythonhosted.org/packages/75/7f/3ef3e360c91f3de120f205c8ce405e9caf9fc52ef14b65d37073e322c114/mypy-1.20.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:b3a49064504be59e59da664c5e149edc1f26c67c4f8e8456f6ba6aba55033018", size = 14918849, upload-time = "2026-03-31T16:51:10.478Z" }, - { url = "https://files.pythonhosted.org/packages/ae/72/af970dfe167ef788df7c5e6109d2ed0229f164432ce828bc9741a4250e64/mypy-1.20.0-cp310-cp310-win_amd64.whl", hash = "sha256:ebea00201737ad4391142808ed16e875add5c17f676e0912b387739f84991e13", size = 10822007, upload-time = "2026-03-31T16:50:25.268Z" }, - { url = "https://files.pythonhosted.org/packages/93/94/ba9065c2ebe5421619aff684b793d953e438a8bfe31a320dd6d1e0706e81/mypy-1.20.0-cp310-cp310-win_arm64.whl", hash = "sha256:e80cf77847d0d3e6e3111b7b25db32a7f8762fd4b9a3a72ce53fe16a2863b281", size = 9756158, upload-time = "2026-03-31T16:48:36.213Z" }, { url = "https://files.pythonhosted.org/packages/6e/1c/74cb1d9993236910286865679d1c616b136b2eae468493aa939431eda410/mypy-1.20.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:4525e7010b1b38334516181c5b81e16180b8e149e6684cee5a727c78186b4e3b", size = 14343972, upload-time = "2026-03-31T16:49:04.887Z" }, { url = "https://files.pythonhosted.org/packages/d5/0d/01399515eca280386e308cf57901e68d3a52af18691941b773b3380c1df8/mypy-1.20.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:a17c5d0bdcca61ce24a35beb828a2d0d323d3fcf387d7512206888c900193367", size = 13225007, upload-time = "2026-03-31T16:50:08.151Z" }, { url = "https://files.pythonhosted.org/packages/56/ac/b4ba5094fb2d7fe9d2037cd8d18bbe02bcf68fd22ab9ff013f55e57ba095/mypy-1.20.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f75ff57defcd0f1d6e006d721ccdec6c88d4f6a7816eb92f1c4890d979d9ee62", size = 13663752, upload-time = "2026-03-31T16:49:26.064Z" }, @@ -712,38 +612,14 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/79/7b/2c79738432f5c924bef5071f933bcc9efd0473bac3b4aa584a6f7c1c8df8/mypy_extensions-1.1.0-py3-none-any.whl", hash = "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505", size = 4963, upload-time = "2025-04-22T14:54:22.983Z" }, ] -[[package]] -name = "myst-parser" -version = "4.0.1" -source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version < '3.11'", -] -dependencies = [ - { name = "docutils", version = "0.21.2", source = { registry = "https://pypi.org/simple" } }, - { name = "jinja2" }, - { name = "markdown-it-py", version = "3.0.0", source = { registry = "https://pypi.org/simple" } }, - { name = "mdit-py-plugins" }, - { name = "pyyaml" }, - { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" } }, -] -sdist = { url = "https://files.pythonhosted.org/packages/66/a5/9626ba4f73555b3735ad86247a8077d4603aa8628537687c839ab08bfe44/myst_parser-4.0.1.tar.gz", hash = "sha256:5cfea715e4f3574138aecbf7d54132296bfd72bb614d31168f48c477a830a7c4", size = 93985, upload-time = "2025-02-12T10:53:03.833Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/5f/df/76d0321c3797b54b60fef9ec3bd6f4cfd124b9e422182156a1dd418722cf/myst_parser-4.0.1-py3-none-any.whl", hash = "sha256:9134e88959ec3b5780aedf8a99680ea242869d012e8821db3126d427edc9c95d", size = 84579, upload-time = "2025-02-12T10:53:02.078Z" }, -] - [[package]] name = "myst-parser" version = "5.0.0" source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version >= '3.12'", - "python_full_version == '3.11.*'", -] dependencies = [ - { name = "docutils", version = "0.22.4", source = { registry = "https://pypi.org/simple" } }, + { name = "docutils" }, { name = "jinja2" }, - { name = "markdown-it-py", version = "4.0.0", source = { registry = "https://pypi.org/simple" } }, + { name = "markdown-it-py" }, { name = "mdit-py-plugins" }, { name = "pyyaml" }, { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, @@ -778,8 +654,7 @@ version = "2.5.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "packaging" }, - { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" }, + { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, { name = "sphinx", version = "9.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" }, { name = "sphinx-notfound-page" }, ] @@ -859,7 +734,6 @@ version = "1.10.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "packaging" }, - { name = "tomli", marker = "python_full_version < '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/45/7b/c0e1333b61d41c69e59e5366e727b18c4992688caf0de1be10b3e5265f6b/pyproject_api-1.10.0.tar.gz", hash = "sha256:40c6f2d82eebdc4afee61c773ed208c04c19db4c4a60d97f8d7be3ebc0bbb330", size = 22785, upload-time = "2025-10-09T19:12:27.21Z" } wheels = [ @@ -885,12 +759,10 @@ version = "9.0.2" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "colorama", marker = "sys_platform == 'win32'" }, - { name = "exceptiongroup", marker = "python_full_version < '3.11'" }, { name = "iniconfig" }, { name = "packaging" }, { name = "pluggy" }, { name = "pygments" }, - { name = "tomli", marker = "python_full_version < '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/d1/db/7ef3487e0fb0049ddb5ce41d3a49c235bf9ad299b6a25d5780a89f19230f/pytest-9.0.2.tar.gz", hash = "sha256:75186651a92bd89611d1d9fc20f0b4345fd827c41ccd5c299a868a05d70edf11", size = 1568901, upload-time = "2025-12-06T21:30:51.014Z" } wheels = [ @@ -941,15 +813,6 @@ version = "6.0.3" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/05/8e/961c0007c59b8dd7729d542c61a4d537767a59645b82a0b521206e1e25c2/pyyaml-6.0.3.tar.gz", hash = "sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f", size = 130960, upload-time = "2025-09-25T21:33:16.546Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/f4/a0/39350dd17dd6d6c6507025c0e53aef67a9293a6d37d3511f23ea510d5800/pyyaml-6.0.3-cp310-cp310-macosx_10_13_x86_64.whl", hash = "sha256:214ed4befebe12df36bcc8bc2b64b396ca31be9304b8f59e25c11cf94a4c033b", size = 184227, upload-time = "2025-09-25T21:31:46.04Z" }, - { url = "https://files.pythonhosted.org/packages/05/14/52d505b5c59ce73244f59c7a50ecf47093ce4765f116cdb98286a71eeca2/pyyaml-6.0.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:02ea2dfa234451bbb8772601d7b8e426c2bfa197136796224e50e35a78777956", size = 174019, upload-time = "2025-09-25T21:31:47.706Z" }, - { url = "https://files.pythonhosted.org/packages/43/f7/0e6a5ae5599c838c696adb4e6330a59f463265bfa1e116cfd1fbb0abaaae/pyyaml-6.0.3-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b30236e45cf30d2b8e7b3e85881719e98507abed1011bf463a8fa23e9c3e98a8", size = 740646, upload-time = "2025-09-25T21:31:49.21Z" }, - { url = "https://files.pythonhosted.org/packages/2f/3a/61b9db1d28f00f8fd0ae760459a5c4bf1b941baf714e207b6eb0657d2578/pyyaml-6.0.3-cp310-cp310-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:66291b10affd76d76f54fad28e22e51719ef9ba22b29e1d7d03d6777a9174198", size = 840793, upload-time = "2025-09-25T21:31:50.735Z" }, - { url = "https://files.pythonhosted.org/packages/7a/1e/7acc4f0e74c4b3d9531e24739e0ab832a5edf40e64fbae1a9c01941cabd7/pyyaml-6.0.3-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9c7708761fccb9397fe64bbc0395abcae8c4bf7b0eac081e12b809bf47700d0b", size = 770293, upload-time = "2025-09-25T21:31:51.828Z" }, - { url = "https://files.pythonhosted.org/packages/8b/ef/abd085f06853af0cd59fa5f913d61a8eab65d7639ff2a658d18a25d6a89d/pyyaml-6.0.3-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:418cf3f2111bc80e0933b2cd8cd04f286338bb88bdc7bc8e6dd775ebde60b5e0", size = 732872, upload-time = "2025-09-25T21:31:53.282Z" }, - { url = "https://files.pythonhosted.org/packages/1f/15/2bc9c8faf6450a8b3c9fc5448ed869c599c0a74ba2669772b1f3a0040180/pyyaml-6.0.3-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:5e0b74767e5f8c593e8c9b5912019159ed0533c70051e9cce3e8b6aa699fcd69", size = 758828, upload-time = "2025-09-25T21:31:54.807Z" }, - { url = "https://files.pythonhosted.org/packages/a3/00/531e92e88c00f4333ce359e50c19b8d1de9fe8d581b1534e35ccfbc5f393/pyyaml-6.0.3-cp310-cp310-win32.whl", hash = "sha256:28c8d926f98f432f88adc23edf2e6d4921ac26fb084b028c733d01868d19007e", size = 142415, upload-time = "2025-09-25T21:31:55.885Z" }, - { url = "https://files.pythonhosted.org/packages/2a/fa/926c003379b19fca39dd4634818b00dec6c62d87faf628d1394e137354d4/pyyaml-6.0.3-cp310-cp310-win_amd64.whl", hash = "sha256:bdb2c67c6c1390b63c6ff89f210c8fd09d9a1217a465701eac7316313c915e4c", size = 158561, upload-time = "2025-09-25T21:31:57.406Z" }, { url = "https://files.pythonhosted.org/packages/6d/16/a95b6757765b7b031c9374925bb718d55e0a9ba8a1b6a12d25962ea44347/pyyaml-6.0.3-cp311-cp311-macosx_10_13_x86_64.whl", hash = "sha256:44edc647873928551a01e7a563d7452ccdebee747728c1080d881d68af7b997e", size = 185826, upload-time = "2025-09-25T21:31:58.655Z" }, { url = "https://files.pythonhosted.org/packages/16/19/13de8e4377ed53079ee996e1ab0a9c33ec2faf808a4647b7b4c0d46dd239/pyyaml-6.0.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:652cb6edd41e718550aad172851962662ff2681490a8a711af6a4d288dd96824", size = 175577, upload-time = "2025-09-25T21:32:00.088Z" }, { url = "https://files.pythonhosted.org/packages/0c/62/d2eb46264d4b157dae1275b573017abec435397aa59cbcdab6fc978a8af4/pyyaml-6.0.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:10892704fc220243f5305762e276552a0395f7beb4dbf9b14ec8fd43b57f126c", size = 775556, upload-time = "2025-09-25T21:32:01.31Z" }, @@ -1057,49 +920,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/c8/78/3565d011c61f5a43488987ee32b6f3f656e7f107ac2782dd57bdd7d91d9a/snowballstemmer-3.0.1-py3-none-any.whl", hash = "sha256:6cd7b3897da8d6c9ffb968a6781fa6532dce9c3618a4b127d920dab764a19064", size = 103274, upload-time = "2025-05-09T16:34:50.371Z" }, ] -[[package]] -name = "sphinx" -version = "8.1.3" -source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version < '3.11'", -] -dependencies = [ - { name = "alabaster" }, - { name = "babel" }, - { name = "colorama", marker = "sys_platform == 'win32'" }, - { name = "docutils", version = "0.21.2", source = { registry = "https://pypi.org/simple" } }, - { name = "imagesize" }, - { name = "jinja2" }, - { name = "packaging" }, - { name = "pygments" }, - { name = "requests" }, - { name = "snowballstemmer" }, - { name = "sphinxcontrib-applehelp" }, - { name = "sphinxcontrib-devhelp" }, - { name = "sphinxcontrib-htmlhelp" }, - { name = "sphinxcontrib-jsmath" }, - { name = "sphinxcontrib-qthelp" }, - { name = "sphinxcontrib-serializinghtml" }, - { name = "tomli" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/6f/6d/be0b61178fe2cdcb67e2a92fc9ebb488e3c51c4f74a36a7824c0adf23425/sphinx-8.1.3.tar.gz", hash = "sha256:43c1911eecb0d3e161ad78611bc905d1ad0e523e4ddc202a58a821773dc4c927", size = 8184611, upload-time = "2024-10-13T20:27:13.93Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/26/60/1ddff83a56d33aaf6f10ec8ce84b4c007d9368b21008876fceda7e7381ef/sphinx-8.1.3-py3-none-any.whl", hash = "sha256:09719015511837b76bf6e03e42eb7595ac8c2e41eeb9c29c5b755c6b677992a2", size = 3487125, upload-time = "2024-10-13T20:27:10.448Z" }, -] - [[package]] name = "sphinx" version = "9.0.4" source = { registry = "https://pypi.org/simple" } resolution-markers = [ - "python_full_version == '3.11.*'", + "python_full_version < '3.12'", ] dependencies = [ { name = "alabaster" }, { name = "babel" }, { name = "colorama", marker = "sys_platform == 'win32'" }, - { name = "docutils", version = "0.22.4", source = { registry = "https://pypi.org/simple" } }, + { name = "docutils" }, { name = "imagesize" }, { name = "jinja2" }, { name = "packaging" }, @@ -1130,7 +962,7 @@ dependencies = [ { name = "alabaster" }, { name = "babel" }, { name = "colorama", marker = "sys_platform == 'win32'" }, - { name = "docutils", version = "0.22.4", source = { registry = "https://pypi.org/simple" } }, + { name = "docutils" }, { name = "imagesize" }, { name = "jinja2" }, { name = "packaging" }, @@ -1150,34 +982,10 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/73/f7/b1884cb3188ab181fc81fa00c266699dab600f927a964df02ec3d5d1916a/sphinx-9.1.0-py3-none-any.whl", hash = "sha256:c84fdd4e782504495fe4f2c0b3413d6c2bf388589bb352d439b2a3bb99991978", size = 3921742, upload-time = "2025-12-31T15:09:25.561Z" }, ] -[[package]] -name = "sphinx-autobuild" -version = "2024.10.3" -source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version < '3.11'", -] -dependencies = [ - { name = "colorama" }, - { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" } }, - { name = "starlette" }, - { name = "uvicorn" }, - { name = "watchfiles" }, - { name = "websockets" }, -] -sdist = { url = "https://files.pythonhosted.org/packages/a5/2c/155e1de2c1ba96a72e5dba152c509a8b41e047ee5c2def9e9f0d812f8be7/sphinx_autobuild-2024.10.3.tar.gz", hash = "sha256:248150f8f333e825107b6d4b86113ab28fa51750e5f9ae63b59dc339be951fb1", size = 14023, upload-time = "2024-10-02T23:15:30.172Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/18/c0/eba125db38c84d3c74717008fd3cb5000b68cd7e2cbafd1349c6a38c3d3b/sphinx_autobuild-2024.10.3-py3-none-any.whl", hash = "sha256:158e16c36f9d633e613c9aaf81c19b0fc458ca78b112533b20dafcda430d60fa", size = 11908, upload-time = "2024-10-02T23:15:28.739Z" }, -] - [[package]] name = "sphinx-autobuild" version = "2025.8.25" source = { registry = "https://pypi.org/simple" } -resolution-markers = [ - "python_full_version >= '3.12'", - "python_full_version == '3.11.*'", -] dependencies = [ { name = "colorama" }, { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, @@ -1197,8 +1005,7 @@ name = "sphinx-notfound-page" version = "1.1.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" }, + { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, { name = "sphinx", version = "9.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/6a/b2/67603444a8ee97b4a8ea71b0a9d6bab1727ed65e362c87e02f818ee57b8a/sphinx_notfound_page-1.1.0.tar.gz", hash = "sha256:913e1754370bb3db201d9300d458a8b8b5fb22e9246a816643a819a9ea2b8067", size = 7392, upload-time = "2025-01-28T18:45:02.871Z" } @@ -1211,11 +1018,9 @@ name = "sphinx-tabs" version = "3.5.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "docutils", version = "0.21.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "docutils", version = "0.22.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, + { name = "docutils" }, { name = "pygments" }, - { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" }, + { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, { name = "sphinx", version = "9.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/ce/30/ca5b0de830f369968d8e3483dd45a8908fd10169c05cd9837f0bd075982e/sphinx_tabs-3.5.0.tar.gz", hash = "sha256:91dba1187e4c35fd37380a56ac228bbd54c6c649b2351829f3bf033718277537", size = 17006, upload-time = "2026-03-03T23:00:30.404Z" } @@ -1264,8 +1069,7 @@ name = "sphinxcontrib-log-cabinet" version = "1.0.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, - { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" }, + { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, { name = "sphinx", version = "9.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/75/26/0687391e10c605a4d0c7ebe118c57c51ecc687128bcdae5803d9b96def81/sphinxcontrib-log-cabinet-1.0.1.tar.gz", hash = "sha256:103b2e62df4e57abb943bea05ee9c2beb7da922222c8b77314ffd6ab9901c558", size = 4072, upload-time = "2019-07-05T23:22:34.596Z" } @@ -1304,60 +1108,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/0b/c9/584bc9651441b4ba60cc4d557d8a547b5aff901af35bda3a4ee30c819b82/starlette-1.0.0-py3-none-any.whl", hash = "sha256:d3ec55e0bb321692d275455ddfd3df75fff145d009685eb40dc91fc66b03d38b", size = 72651, upload-time = "2026-03-22T18:29:45.111Z" }, ] -[[package]] -name = "tomli" -version = "2.4.1" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/22/de/48c59722572767841493b26183a0d1cc411d54fd759c5607c4590b6563a6/tomli-2.4.1.tar.gz", hash = "sha256:7c7e1a961a0b2f2472c1ac5b69affa0ae1132c39adcb67aba98568702b9cc23f", size = 17543, upload-time = "2026-03-25T20:22:03.828Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/f4/11/db3d5885d8528263d8adc260bb2d28ebf1270b96e98f0e0268d32b8d9900/tomli-2.4.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:f8f0fc26ec2cc2b965b7a3b87cd19c5c6b8c5e5f436b984e85f486d652285c30", size = 154704, upload-time = "2026-03-25T20:21:10.473Z" }, - { url = "https://files.pythonhosted.org/packages/6d/f7/675db52c7e46064a9aa928885a9b20f4124ecb9bc2e1ce74c9106648d202/tomli-2.4.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4ab97e64ccda8756376892c53a72bd1f964e519c77236368527f758fbc36a53a", size = 149454, upload-time = "2026-03-25T20:21:12.036Z" }, - { url = "https://files.pythonhosted.org/packages/61/71/81c50943cf953efa35bce7646caab3cf457a7d8c030b27cfb40d7235f9ee/tomli-2.4.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:96481a5786729fd470164b47cdb3e0e58062a496f455ee41b4403be77cb5a076", size = 237561, upload-time = "2026-03-25T20:21:13.098Z" }, - { url = "https://files.pythonhosted.org/packages/48/c1/f41d9cb618acccca7df82aaf682f9b49013c9397212cb9f53219e3abac37/tomli-2.4.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5a881ab208c0baf688221f8cecc5401bd291d67e38a1ac884d6736cbcd8247e9", size = 243824, upload-time = "2026-03-25T20:21:14.569Z" }, - { url = "https://files.pythonhosted.org/packages/22/e4/5a816ecdd1f8ca51fb756ef684b90f2780afc52fc67f987e3c61d800a46d/tomli-2.4.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:47149d5bd38761ac8be13a84864bf0b7b70bc051806bc3669ab1cbc56216b23c", size = 242227, upload-time = "2026-03-25T20:21:15.712Z" }, - { url = "https://files.pythonhosted.org/packages/6b/49/2b2a0ef529aa6eec245d25f0c703e020a73955ad7edf73e7f54ddc608aa5/tomli-2.4.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:ec9bfaf3ad2df51ace80688143a6a4ebc09a248f6ff781a9945e51937008fcbc", size = 247859, upload-time = "2026-03-25T20:21:17.001Z" }, - { url = "https://files.pythonhosted.org/packages/83/bd/6c1a630eaca337e1e78c5903104f831bda934c426f9231429396ce3c3467/tomli-2.4.1-cp311-cp311-win32.whl", hash = "sha256:ff2983983d34813c1aeb0fa89091e76c3a22889ee83ab27c5eeb45100560c049", size = 97204, upload-time = "2026-03-25T20:21:18.079Z" }, - { url = "https://files.pythonhosted.org/packages/42/59/71461df1a885647e10b6bb7802d0b8e66480c61f3f43079e0dcd315b3954/tomli-2.4.1-cp311-cp311-win_amd64.whl", hash = "sha256:5ee18d9ebdb417e384b58fe414e8d6af9f4e7a0ae761519fb50f721de398dd4e", size = 108084, upload-time = "2026-03-25T20:21:18.978Z" }, - { url = "https://files.pythonhosted.org/packages/b8/83/dceca96142499c069475b790e7913b1044c1a4337e700751f48ed723f883/tomli-2.4.1-cp311-cp311-win_arm64.whl", hash = "sha256:c2541745709bad0264b7d4705ad453b76ccd191e64aa6f0fc66b69a293a45ece", size = 95285, upload-time = "2026-03-25T20:21:20.309Z" }, - { url = "https://files.pythonhosted.org/packages/c1/ba/42f134a3fe2b370f555f44b1d72feebb94debcab01676bf918d0cb70e9aa/tomli-2.4.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:c742f741d58a28940ce01d58f0ab2ea3ced8b12402f162f4d534dfe18ba1cd6a", size = 155924, upload-time = "2026-03-25T20:21:21.626Z" }, - { url = "https://files.pythonhosted.org/packages/dc/c7/62d7a17c26487ade21c5422b646110f2162f1fcc95980ef7f63e73c68f14/tomli-2.4.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:7f86fd587c4ed9dd76f318225e7d9b29cfc5a9d43de44e5754db8d1128487085", size = 150018, upload-time = "2026-03-25T20:21:23.002Z" }, - { url = "https://files.pythonhosted.org/packages/5c/05/79d13d7c15f13bdef410bdd49a6485b1c37d28968314eabee452c22a7fda/tomli-2.4.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ff18e6a727ee0ab0388507b89d1bc6a22b138d1e2fa56d1ad494586d61d2eae9", size = 244948, upload-time = "2026-03-25T20:21:24.04Z" }, - { url = "https://files.pythonhosted.org/packages/10/90/d62ce007a1c80d0b2c93e02cab211224756240884751b94ca72df8a875ca/tomli-2.4.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:136443dbd7e1dee43c68ac2694fde36b2849865fa258d39bf822c10e8068eac5", size = 253341, upload-time = "2026-03-25T20:21:25.177Z" }, - { url = "https://files.pythonhosted.org/packages/1a/7e/caf6496d60152ad4ed09282c1885cca4eea150bfd007da84aea07bcc0a3e/tomli-2.4.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:5e262d41726bc187e69af7825504c933b6794dc3fbd5945e41a79bb14c31f585", size = 248159, upload-time = "2026-03-25T20:21:26.364Z" }, - { url = "https://files.pythonhosted.org/packages/99/e7/c6f69c3120de34bbd882c6fba7975f3d7a746e9218e56ab46a1bc4b42552/tomli-2.4.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:5cb41aa38891e073ee49d55fbc7839cfdb2bc0e600add13874d048c94aadddd1", size = 253290, upload-time = "2026-03-25T20:21:27.46Z" }, - { url = "https://files.pythonhosted.org/packages/d6/2f/4a3c322f22c5c66c4b836ec58211641a4067364f5dcdd7b974b4c5da300c/tomli-2.4.1-cp312-cp312-win32.whl", hash = "sha256:da25dc3563bff5965356133435b757a795a17b17d01dbc0f42fb32447ddfd917", size = 98141, upload-time = "2026-03-25T20:21:28.492Z" }, - { url = "https://files.pythonhosted.org/packages/24/22/4daacd05391b92c55759d55eaee21e1dfaea86ce5c571f10083360adf534/tomli-2.4.1-cp312-cp312-win_amd64.whl", hash = "sha256:52c8ef851d9a240f11a88c003eacb03c31fc1c9c4ec64a99a0f922b93874fda9", size = 108847, upload-time = "2026-03-25T20:21:29.386Z" }, - { url = "https://files.pythonhosted.org/packages/68/fd/70e768887666ddd9e9f5d85129e84910f2db2796f9096aa02b721a53098d/tomli-2.4.1-cp312-cp312-win_arm64.whl", hash = "sha256:f758f1b9299d059cc3f6546ae2af89670cb1c4d48ea29c3cacc4fe7de3058257", size = 95088, upload-time = "2026-03-25T20:21:30.677Z" }, - { url = "https://files.pythonhosted.org/packages/07/06/b823a7e818c756d9a7123ba2cda7d07bc2dd32835648d1a7b7b7a05d848d/tomli-2.4.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:36d2bd2ad5fb9eaddba5226aa02c8ec3fa4f192631e347b3ed28186d43be6b54", size = 155866, upload-time = "2026-03-25T20:21:31.65Z" }, - { url = "https://files.pythonhosted.org/packages/14/6f/12645cf7f08e1a20c7eb8c297c6f11d31c1b50f316a7e7e1e1de6e2e7b7e/tomli-2.4.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:eb0dc4e38e6a1fd579e5d50369aa2e10acfc9cace504579b2faabb478e76941a", size = 149887, upload-time = "2026-03-25T20:21:33.028Z" }, - { url = "https://files.pythonhosted.org/packages/5c/e0/90637574e5e7212c09099c67ad349b04ec4d6020324539297b634a0192b0/tomli-2.4.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c7f2c7f2b9ca6bdeef8f0fa897f8e05085923eb091721675170254cbc5b02897", size = 243704, upload-time = "2026-03-25T20:21:34.51Z" }, - { url = "https://files.pythonhosted.org/packages/10/8f/d3ddb16c5a4befdf31a23307f72828686ab2096f068eaf56631e136c1fdd/tomli-2.4.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:f3c6818a1a86dd6dca7ddcaaf76947d5ba31aecc28cb1b67009a5877c9a64f3f", size = 251628, upload-time = "2026-03-25T20:21:36.012Z" }, - { url = "https://files.pythonhosted.org/packages/e3/f1/dbeeb9116715abee2485bf0a12d07a8f31af94d71608c171c45f64c0469d/tomli-2.4.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:d312ef37c91508b0ab2cee7da26ec0b3ed2f03ce12bd87a588d771ae15dcf82d", size = 247180, upload-time = "2026-03-25T20:21:37.136Z" }, - { url = "https://files.pythonhosted.org/packages/d3/74/16336ffd19ed4da28a70959f92f506233bd7cfc2332b20bdb01591e8b1d1/tomli-2.4.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:51529d40e3ca50046d7606fa99ce3956a617f9b36380da3b7f0dd3dd28e68cb5", size = 251674, upload-time = "2026-03-25T20:21:38.298Z" }, - { url = "https://files.pythonhosted.org/packages/16/f9/229fa3434c590ddf6c0aa9af64d3af4b752540686cace29e6281e3458469/tomli-2.4.1-cp313-cp313-win32.whl", hash = "sha256:2190f2e9dd7508d2a90ded5ed369255980a1bcdd58e52f7fe24b8162bf9fedbd", size = 97976, upload-time = "2026-03-25T20:21:39.316Z" }, - { url = "https://files.pythonhosted.org/packages/6a/1e/71dfd96bcc1c775420cb8befe7a9d35f2e5b1309798f009dca17b7708c1e/tomli-2.4.1-cp313-cp313-win_amd64.whl", hash = "sha256:8d65a2fbf9d2f8352685bc1364177ee3923d6baf5e7f43ea4959d7d8bc326a36", size = 108755, upload-time = "2026-03-25T20:21:40.248Z" }, - { url = "https://files.pythonhosted.org/packages/83/7a/d34f422a021d62420b78f5c538e5b102f62bea616d1d75a13f0a88acb04a/tomli-2.4.1-cp313-cp313-win_arm64.whl", hash = "sha256:4b605484e43cdc43f0954ddae319fb75f04cc10dd80d830540060ee7cd0243cd", size = 95265, upload-time = "2026-03-25T20:21:41.219Z" }, - { url = "https://files.pythonhosted.org/packages/3c/fb/9a5c8d27dbab540869f7c1f8eb0abb3244189ce780ba9cd73f3770662072/tomli-2.4.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:fd0409a3653af6c147209d267a0e4243f0ae46b011aa978b1080359fddc9b6cf", size = 155726, upload-time = "2026-03-25T20:21:42.23Z" }, - { url = "https://files.pythonhosted.org/packages/62/05/d2f816630cc771ad836af54f5001f47a6f611d2d39535364f148b6a92d6b/tomli-2.4.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:a120733b01c45e9a0c34aeef92bf0cf1d56cfe81ed9d47d562f9ed591a9828ac", size = 149859, upload-time = "2026-03-25T20:21:43.386Z" }, - { url = "https://files.pythonhosted.org/packages/ce/48/66341bdb858ad9bd0ceab5a86f90eddab127cf8b046418009f2125630ecb/tomli-2.4.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:559db847dc486944896521f68d8190be1c9e719fced785720d2216fe7022b662", size = 244713, upload-time = "2026-03-25T20:21:44.474Z" }, - { url = "https://files.pythonhosted.org/packages/df/6d/c5fad00d82b3c7a3ab6189bd4b10e60466f22cfe8a08a9394185c8a8111c/tomli-2.4.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:01f520d4f53ef97964a240a035ec2a869fe1a37dde002b57ebc4417a27ccd853", size = 252084, upload-time = "2026-03-25T20:21:45.62Z" }, - { url = "https://files.pythonhosted.org/packages/00/71/3a69e86f3eafe8c7a59d008d245888051005bd657760e96d5fbfb0b740c2/tomli-2.4.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7f94b27a62cfad8496c8d2513e1a222dd446f095fca8987fceef261225538a15", size = 247973, upload-time = "2026-03-25T20:21:46.937Z" }, - { url = "https://files.pythonhosted.org/packages/67/50/361e986652847fec4bd5e4a0208752fbe64689c603c7ae5ea7cb16b1c0ca/tomli-2.4.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:ede3e6487c5ef5d28634ba3f31f989030ad6af71edfb0055cbbd14189ff240ba", size = 256223, upload-time = "2026-03-25T20:21:48.467Z" }, - { url = "https://files.pythonhosted.org/packages/8c/9a/b4173689a9203472e5467217e0154b00e260621caa227b6fa01feab16998/tomli-2.4.1-cp314-cp314-win32.whl", hash = "sha256:3d48a93ee1c9b79c04bb38772ee1b64dcf18ff43085896ea460ca8dec96f35f6", size = 98973, upload-time = "2026-03-25T20:21:49.526Z" }, - { url = "https://files.pythonhosted.org/packages/14/58/640ac93bf230cd27d002462c9af0d837779f8773bc03dee06b5835208214/tomli-2.4.1-cp314-cp314-win_amd64.whl", hash = "sha256:88dceee75c2c63af144e456745e10101eb67361050196b0b6af5d717254dddf7", size = 109082, upload-time = "2026-03-25T20:21:50.506Z" }, - { url = "https://files.pythonhosted.org/packages/d5/2f/702d5e05b227401c1068f0d386d79a589bb12bf64c3d2c72ce0631e3bc49/tomli-2.4.1-cp314-cp314-win_arm64.whl", hash = "sha256:b8c198f8c1805dc42708689ed6864951fd2494f924149d3e4bce7710f8eb5232", size = 96490, upload-time = "2026-03-25T20:21:51.474Z" }, - { url = "https://files.pythonhosted.org/packages/45/4b/b877b05c8ba62927d9865dd980e34a755de541eb65fffba52b4cc495d4d2/tomli-2.4.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:d4d8fe59808a54658fcc0160ecfb1b30f9089906c50b23bcb4c69eddc19ec2b4", size = 164263, upload-time = "2026-03-25T20:21:52.543Z" }, - { url = "https://files.pythonhosted.org/packages/24/79/6ab420d37a270b89f7195dec5448f79400d9e9c1826df982f3f8e97b24fd/tomli-2.4.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:7008df2e7655c495dd12d2a4ad038ff878d4ca4b81fccaf82b714e07eae4402c", size = 160736, upload-time = "2026-03-25T20:21:53.674Z" }, - { url = "https://files.pythonhosted.org/packages/02/e0/3630057d8eb170310785723ed5adcdfb7d50cb7e6455f85ba8a3deed642b/tomli-2.4.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1d8591993e228b0c930c4bb0db464bdad97b3289fb981255d6c9a41aedc84b2d", size = 270717, upload-time = "2026-03-25T20:21:55.129Z" }, - { url = "https://files.pythonhosted.org/packages/7a/b4/1613716072e544d1a7891f548d8f9ec6ce2faf42ca65acae01d76ea06bb0/tomli-2.4.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:734e20b57ba95624ecf1841e72b53f6e186355e216e5412de414e3c51e5e3c41", size = 278461, upload-time = "2026-03-25T20:21:56.228Z" }, - { url = "https://files.pythonhosted.org/packages/05/38/30f541baf6a3f6df77b3df16b01ba319221389e2da59427e221ef417ac0c/tomli-2.4.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:8a650c2dbafa08d42e51ba0b62740dae4ecb9338eefa093aa5c78ceb546fcd5c", size = 274855, upload-time = "2026-03-25T20:21:57.653Z" }, - { url = "https://files.pythonhosted.org/packages/77/a3/ec9dd4fd2c38e98de34223b995a3b34813e6bdadf86c75314c928350ed14/tomli-2.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:504aa796fe0569bb43171066009ead363de03675276d2d121ac1a4572397870f", size = 283144, upload-time = "2026-03-25T20:21:59.089Z" }, - { url = "https://files.pythonhosted.org/packages/ef/be/605a6261cac79fba2ec0c9827e986e00323a1945700969b8ee0b30d85453/tomli-2.4.1-cp314-cp314t-win32.whl", hash = "sha256:b1d22e6e9387bf4739fbe23bfa80e93f6b0373a7f1b96c6227c32bef95a4d7a8", size = 108683, upload-time = "2026-03-25T20:22:00.214Z" }, - { url = "https://files.pythonhosted.org/packages/12/64/da524626d3b9cc40c168a13da8335fe1c51be12c0a63685cc6db7308daae/tomli-2.4.1-cp314-cp314t-win_amd64.whl", hash = "sha256:2c1c351919aca02858f740c6d33adea0c5deea37f9ecca1cc1ef9e884a619d26", size = 121196, upload-time = "2026-03-25T20:22:01.169Z" }, - { url = "https://files.pythonhosted.org/packages/5a/cd/e80b62269fc78fc36c9af5a6b89c835baa8af28ff5ad28c7028d60860320/tomli-2.4.1-cp314-cp314t-win_arm64.whl", hash = "sha256:eab21f45c7f66c13f2a9e0e1535309cee140182a9cdae1e041d02e47291e8396", size = 100393, upload-time = "2026-03-25T20:22:02.137Z" }, - { url = "https://files.pythonhosted.org/packages/7b/61/cceae43728b7de99d9b847560c262873a1f6c98202171fd5ed62640b494b/tomli-2.4.1-py3-none-any.whl", hash = "sha256:0d85819802132122da43cb86656f8d1f8c6587d54ae7dcaf30e90533028b49fe", size = 14583, upload-time = "2026-03-25T20:22:03.012Z" }, -] - [[package]] name = "tomli-w" version = "1.2.0" @@ -1380,9 +1130,7 @@ dependencies = [ { name = "pluggy" }, { name = "pyproject-api" }, { name = "python-discovery" }, - { name = "tomli", marker = "python_full_version < '3.11'" }, { name = "tomli-w" }, - { name = "typing-extensions", marker = "python_full_version < '3.11'" }, { name = "virtualenv" }, ] sdist = { url = "https://files.pythonhosted.org/packages/59/6e/ad613e2516a653dc6591186aab726d84d769c6352c0c3dc8fc8ed213168b/tox-4.52.0.tar.gz", hash = "sha256:6054abf5c8b61d58776fbec991f9bf0d34bb883862beb93d2fe55601ef3977c9", size = 273077, upload-time = "2026-03-30T20:33:26.958Z" } @@ -1408,7 +1156,6 @@ version = "1.34.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "packaging" }, - { name = "tomli", marker = "python_full_version < '3.11'" }, { name = "tox" }, ] sdist = { url = "https://files.pythonhosted.org/packages/34/28/d967dd5cbdb099e50974d4f44d181e1642596776435b68b22b3893634c4c/tox_uv_bare-1.34.0.tar.gz", hash = "sha256:257b637796bc18179e158923ae597475f9d891223bf5de065f144455fd5fafd1", size = 29169, upload-time = "2026-03-30T23:31:43.57Z" } @@ -1467,7 +1214,6 @@ source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "click" }, { name = "h11" }, - { name = "typing-extensions", marker = "python_full_version < '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/62/f2/368268300fb8af33743508d738ef7bb4d56afdb46c6d9c0fa3dd515df171/uvicorn-0.43.0.tar.gz", hash = "sha256:ab1652d2fb23abf124f36ccc399828558880def222c3cb3d98d24021520dc6e8", size = 85686, upload-time = "2026-04-03T18:37:48.984Z" } wheels = [ @@ -1483,7 +1229,6 @@ dependencies = [ { name = "filelock" }, { name = "platformdirs" }, { name = "python-discovery" }, - { name = "typing-extensions", marker = "python_full_version < '3.11'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/aa/92/58199fe10049f9703c2666e809c4f686c54ef0a68b0f6afccf518c0b1eb9/virtualenv-21.2.0.tar.gz", hash = "sha256:1720dc3a62ef5b443092e3f499228599045d7fea4c79199770499df8becf9098", size = 5840618, upload-time = "2026-03-09T17:24:38.013Z" } wheels = [ @@ -1499,18 +1244,6 @@ dependencies = [ ] sdist = { url = "https://files.pythonhosted.org/packages/c2/c9/8869df9b2a2d6c59d79220a4db37679e74f807c559ffe5265e08b227a210/watchfiles-1.1.1.tar.gz", hash = "sha256:a173cb5c16c4f40ab19cecf48a534c409f7ea983ab8fed0741304a1c0a31b3f2", size = 94440, upload-time = "2025-10-14T15:06:21.08Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/a7/1a/206e8cf2dd86fddf939165a57b4df61607a1e0add2785f170a3f616b7d9f/watchfiles-1.1.1-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:eef58232d32daf2ac67f42dea51a2c80f0d03379075d44a587051e63cc2e368c", size = 407318, upload-time = "2025-10-14T15:04:18.753Z" }, - { url = "https://files.pythonhosted.org/packages/b3/0f/abaf5262b9c496b5dad4ed3c0e799cbecb1f8ea512ecb6ddd46646a9fca3/watchfiles-1.1.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:03fa0f5237118a0c5e496185cafa92878568b652a2e9a9382a5151b1a0380a43", size = 394478, upload-time = "2025-10-14T15:04:20.297Z" }, - { url = "https://files.pythonhosted.org/packages/b1/04/9cc0ba88697b34b755371f5ace8d3a4d9a15719c07bdc7bd13d7d8c6a341/watchfiles-1.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8ca65483439f9c791897f7db49202301deb6e15fe9f8fe2fed555bf986d10c31", size = 449894, upload-time = "2025-10-14T15:04:21.527Z" }, - { url = "https://files.pythonhosted.org/packages/d2/9c/eda4615863cd8621e89aed4df680d8c3ec3da6a4cf1da113c17decd87c7f/watchfiles-1.1.1-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f0ab1c1af0cb38e3f598244c17919fb1a84d1629cc08355b0074b6d7f53138ac", size = 459065, upload-time = "2025-10-14T15:04:22.795Z" }, - { url = "https://files.pythonhosted.org/packages/84/13/f28b3f340157d03cbc8197629bc109d1098764abe1e60874622a0be5c112/watchfiles-1.1.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3bc570d6c01c206c46deb6e935a260be44f186a2f05179f52f7fcd2be086a94d", size = 488377, upload-time = "2025-10-14T15:04:24.138Z" }, - { url = "https://files.pythonhosted.org/packages/86/93/cfa597fa9389e122488f7ffdbd6db505b3b915ca7435ecd7542e855898c2/watchfiles-1.1.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e84087b432b6ac94778de547e08611266f1f8ffad28c0ee4c82e028b0fc5966d", size = 595837, upload-time = "2025-10-14T15:04:25.057Z" }, - { url = "https://files.pythonhosted.org/packages/57/1e/68c1ed5652b48d89fc24d6af905d88ee4f82fa8bc491e2666004e307ded1/watchfiles-1.1.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:620bae625f4cb18427b1bb1a2d9426dc0dd5a5ba74c7c2cdb9de405f7b129863", size = 473456, upload-time = "2025-10-14T15:04:26.497Z" }, - { url = "https://files.pythonhosted.org/packages/d5/dc/1a680b7458ffa3b14bb64878112aefc8f2e4f73c5af763cbf0bd43100658/watchfiles-1.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:544364b2b51a9b0c7000a4b4b02f90e9423d97fbbf7e06689236443ebcad81ab", size = 455614, upload-time = "2025-10-14T15:04:27.539Z" }, - { url = "https://files.pythonhosted.org/packages/61/a5/3d782a666512e01eaa6541a72ebac1d3aae191ff4a31274a66b8dd85760c/watchfiles-1.1.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:bbe1ef33d45bc71cf21364df962af171f96ecaeca06bd9e3d0b583efb12aec82", size = 630690, upload-time = "2025-10-14T15:04:28.495Z" }, - { url = "https://files.pythonhosted.org/packages/9b/73/bb5f38590e34687b2a9c47a244aa4dd50c56a825969c92c9c5fc7387cea1/watchfiles-1.1.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:1a0bb430adb19ef49389e1ad368450193a90038b5b752f4ac089ec6942c4dff4", size = 622459, upload-time = "2025-10-14T15:04:29.491Z" }, - { url = "https://files.pythonhosted.org/packages/f1/ac/c9bb0ec696e07a20bd58af5399aeadaef195fb2c73d26baf55180fe4a942/watchfiles-1.1.1-cp310-cp310-win32.whl", hash = "sha256:3f6d37644155fb5beca5378feb8c1708d5783145f2a0f1c4d5a061a210254844", size = 272663, upload-time = "2025-10-14T15:04:30.435Z" }, - { url = "https://files.pythonhosted.org/packages/11/a0/a60c5a7c2ec59fa062d9a9c61d02e3b6abd94d32aac2d8344c4bdd033326/watchfiles-1.1.1-cp310-cp310-win_amd64.whl", hash = "sha256:a36d8efe0f290835fd0f33da35042a1bb5dc0e83cbc092dcf69bce442579e88e", size = 287453, upload-time = "2025-10-14T15:04:31.53Z" }, { url = "https://files.pythonhosted.org/packages/1f/f8/2c5f479fb531ce2f0564eda479faecf253d886b1ab3630a39b7bf7362d46/watchfiles-1.1.1-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:f57b396167a2565a4e8b5e56a5a1c537571733992b226f4f1197d79e94cf0ae5", size = 406529, upload-time = "2025-10-14T15:04:32.899Z" }, { url = "https://files.pythonhosted.org/packages/fe/cd/f515660b1f32f65df671ddf6f85bfaca621aee177712874dc30a97397977/watchfiles-1.1.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:421e29339983e1bebc281fab40d812742268ad057db4aee8c4d2bce0af43b741", size = 394384, upload-time = "2025-10-14T15:04:33.761Z" }, { url = "https://files.pythonhosted.org/packages/7b/c3/28b7dc99733eab43fca2d10f55c86e03bd6ab11ca31b802abac26b23d161/watchfiles-1.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6e43d39a741e972bab5d8100b5cdacf69db64e34eb19b6e9af162bccf63c5cc6", size = 448789, upload-time = "2025-10-14T15:04:34.679Z" }, @@ -1583,10 +1316,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/4f/55/2af26693fd15165c4ff7857e38330e1b61ab8c37d15dc79118cdba115b7a/watchfiles-1.1.1-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8c91ed27800188c2ae96d16e3149f199d62f86c7af5f5f4d2c61a3ed8cd3666c", size = 455072, upload-time = "2025-10-14T15:05:48.928Z" }, { url = "https://files.pythonhosted.org/packages/66/1d/d0d200b10c9311ec25d2273f8aad8c3ef7cc7ea11808022501811208a750/watchfiles-1.1.1-cp314-cp314t-musllinux_1_1_aarch64.whl", hash = "sha256:311ff15a0bae3714ffb603e6ba6dbfba4065ab60865d15a6ec544133bdb21099", size = 629104, upload-time = "2025-10-14T15:05:49.908Z" }, { url = "https://files.pythonhosted.org/packages/e3/bd/fa9bb053192491b3867ba07d2343d9f2252e00811567d30ae8d0f78136fe/watchfiles-1.1.1-cp314-cp314t-musllinux_1_1_x86_64.whl", hash = "sha256:a916a2932da8f8ab582f242c065f5c81bed3462849ca79ee357dd9551b0e9b01", size = 622112, upload-time = "2025-10-14T15:05:50.941Z" }, - { url = "https://files.pythonhosted.org/packages/ba/4c/a888c91e2e326872fa4705095d64acd8aa2fb9c1f7b9bd0588f33850516c/watchfiles-1.1.1-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:17ef139237dfced9da49fb7f2232c86ca9421f666d78c264c7ffca6601d154c3", size = 409611, upload-time = "2025-10-14T15:06:05.809Z" }, - { url = "https://files.pythonhosted.org/packages/1e/c7/5420d1943c8e3ce1a21c0a9330bcf7edafb6aa65d26b21dbb3267c9e8112/watchfiles-1.1.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:672b8adf25b1a0d35c96b5888b7b18699d27d4194bac8beeae75be4b7a3fc9b2", size = 396889, upload-time = "2025-10-14T15:06:07.035Z" }, - { url = "https://files.pythonhosted.org/packages/0c/e5/0072cef3804ce8d3aaddbfe7788aadff6b3d3f98a286fdbee9fd74ca59a7/watchfiles-1.1.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:77a13aea58bc2b90173bc69f2a90de8e282648939a00a602e1dc4ee23e26b66d", size = 451616, upload-time = "2025-10-14T15:06:08.072Z" }, - { url = "https://files.pythonhosted.org/packages/83/4e/b87b71cbdfad81ad7e83358b3e447fedd281b880a03d64a760fe0a11fc2e/watchfiles-1.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0b495de0bb386df6a12b18335a0285dda90260f51bdb505503c02bcd1ce27a8b", size = 458413, upload-time = "2025-10-14T15:06:09.209Z" }, { url = "https://files.pythonhosted.org/packages/d3/8e/e500f8b0b77be4ff753ac94dc06b33d8f0d839377fee1b78e8c8d8f031bf/watchfiles-1.1.1-pp311-pypy311_pp73-macosx_10_12_x86_64.whl", hash = "sha256:db476ab59b6765134de1d4fe96a1a9c96ddf091683599be0f26147ea1b2e4b88", size = 408250, upload-time = "2025-10-14T15:06:10.264Z" }, { url = "https://files.pythonhosted.org/packages/bd/95/615e72cd27b85b61eec764a5ca51bd94d40b5adea5ff47567d9ebc4d275a/watchfiles-1.1.1-pp311-pypy311_pp73-macosx_11_0_arm64.whl", hash = "sha256:89eef07eee5e9d1fda06e38822ad167a044153457e6fd997f8a858ab7564a336", size = 396117, upload-time = "2025-10-14T15:06:11.28Z" }, { url = "https://files.pythonhosted.org/packages/c9/81/e7fe958ce8a7fb5c73cc9fb07f5aeaf755e6aa72498c57d760af760c91f8/watchfiles-1.1.1-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ce19e06cbda693e9e7686358af9cd6f5d61312ab8b00488bc36f5aabbaf77e24", size = 450493, upload-time = "2025-10-14T15:06:12.321Z" }, @@ -1599,15 +1328,6 @@ version = "16.0" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/04/24/4b2031d72e840ce4c1ccb255f693b15c334757fc50023e4db9537080b8c4/websockets-16.0.tar.gz", hash = "sha256:5f6261a5e56e8d5c42a4497b364ea24d94d9563e8fbd44e78ac40879c60179b5", size = 179346, upload-time = "2026-01-10T09:23:47.181Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/20/74/221f58decd852f4b59cc3354cccaf87e8ef695fede361d03dc9a7396573b/websockets-16.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:04cdd5d2d1dacbad0a7bf36ccbcd3ccd5a30ee188f2560b7a62a30d14107b31a", size = 177343, upload-time = "2026-01-10T09:22:21.28Z" }, - { url = "https://files.pythonhosted.org/packages/19/0f/22ef6107ee52ab7f0b710d55d36f5a5d3ef19e8a205541a6d7ffa7994e5a/websockets-16.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:8ff32bb86522a9e5e31439a58addbb0166f0204d64066fb955265c4e214160f0", size = 175021, upload-time = "2026-01-10T09:22:22.696Z" }, - { url = "https://files.pythonhosted.org/packages/10/40/904a4cb30d9b61c0e278899bf36342e9b0208eb3c470324a9ecbaac2a30f/websockets-16.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:583b7c42688636f930688d712885cf1531326ee05effd982028212ccc13e5957", size = 175320, upload-time = "2026-01-10T09:22:23.94Z" }, - { url = "https://files.pythonhosted.org/packages/9d/2f/4b3ca7e106bc608744b1cdae041e005e446124bebb037b18799c2d356864/websockets-16.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:7d837379b647c0c4c2355c2499723f82f1635fd2c26510e1f587d89bc2199e72", size = 183815, upload-time = "2026-01-10T09:22:25.469Z" }, - { url = "https://files.pythonhosted.org/packages/86/26/d40eaa2a46d4302becec8d15b0fc5e45bdde05191e7628405a19cf491ccd/websockets-16.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:df57afc692e517a85e65b72e165356ed1df12386ecb879ad5693be08fac65dde", size = 185054, upload-time = "2026-01-10T09:22:27.101Z" }, - { url = "https://files.pythonhosted.org/packages/b0/ba/6500a0efc94f7373ee8fefa8c271acdfd4dca8bd49a90d4be7ccabfc397e/websockets-16.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:2b9f1e0d69bc60a4a87349d50c09a037a2607918746f07de04df9e43252c77a3", size = 184565, upload-time = "2026-01-10T09:22:28.293Z" }, - { url = "https://files.pythonhosted.org/packages/04/b4/96bf2cee7c8d8102389374a2616200574f5f01128d1082f44102140344cc/websockets-16.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:335c23addf3d5e6a8633f9f8eda77efad001671e80b95c491dd0924587ece0b3", size = 183848, upload-time = "2026-01-10T09:22:30.394Z" }, - { url = "https://files.pythonhosted.org/packages/02/8e/81f40fb00fd125357814e8c3025738fc4ffc3da4b6b4a4472a82ba304b41/websockets-16.0-cp310-cp310-win32.whl", hash = "sha256:37b31c1623c6605e4c00d466c9d633f9b812ea430c11c8a278774a1fde1acfa9", size = 178249, upload-time = "2026-01-10T09:22:32.083Z" }, - { url = "https://files.pythonhosted.org/packages/b4/5f/7e40efe8df57db9b91c88a43690ac66f7b7aa73a11aa6a66b927e44f26fa/websockets-16.0-cp310-cp310-win_amd64.whl", hash = "sha256:8e1dab317b6e77424356e11e99a432b7cb2f3ec8c5ab4dabbcee6add48f72b35", size = 178685, upload-time = "2026-01-10T09:22:33.345Z" }, { url = "https://files.pythonhosted.org/packages/f2/db/de907251b4ff46ae804ad0409809504153b3f30984daf82a1d84a9875830/websockets-16.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:31a52addea25187bde0797a97d6fc3d2f92b6f72a9370792d65a6e84615ac8a8", size = 177340, upload-time = "2026-01-10T09:22:34.539Z" }, { url = "https://files.pythonhosted.org/packages/f3/fa/abe89019d8d8815c8781e90d697dec52523fb8ebe308bf11664e8de1877e/websockets-16.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:417b28978cdccab24f46400586d128366313e8a96312e4b9362a4af504f3bbad", size = 175022, upload-time = "2026-01-10T09:22:36.332Z" }, { url = "https://files.pythonhosted.org/packages/58/5d/88ea17ed1ded2079358b40d31d48abe90a73c9e5819dbcde1606e991e2ad/websockets-16.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:af80d74d4edfa3cb9ed973a0a5ba2b2a549371f8a741e0800cb07becdd20f23d", size = 175319, upload-time = "2026-01-10T09:22:37.602Z" }, From d77c32b28743b93111a2835133605d4a2abfe949 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Wed, 18 Nov 2026 23:42:33 -0800 Subject: [PATCH 07/18] Move parser to _parser. --- src/click/{parser.py => _parser.py} | 0 src/click/core.py | 2 +- src/click/formatting.py | 2 +- tests/test_options.py | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename src/click/{parser.py => _parser.py} (100%) diff --git a/src/click/parser.py b/src/click/_parser.py similarity index 100% rename from src/click/parser.py rename to src/click/_parser.py diff --git a/src/click/core.py b/src/click/core.py index 1280da26a..01270cfdf 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -23,6 +23,7 @@ from types import TracebackType from . import types +from ._parser import _split_opt from ._utils import FLAG_NEEDS_VALUE from ._utils import UNSET from .exceptions import Abort @@ -40,7 +41,6 @@ from .formatting import join_options from .globals import pop_context from .globals import push_context -from .parser import _split_opt from .termui import confirm from .termui import prompt from .termui import style diff --git a/src/click/formatting.py b/src/click/formatting.py index b9f86b798..3da541a2d 100644 --- a/src/click/formatting.py +++ b/src/click/formatting.py @@ -5,7 +5,7 @@ from gettext import gettext as _ from ._compat import term_len -from .parser import _split_opt +from ._parser import _split_opt # Can force a width. This is used by the test system FORCED_WIDTH: int | None = None diff --git a/tests/test_options.py b/tests/test_options.py index 260c72bfb..2815a86ac 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -13,8 +13,8 @@ import click from click import Option from click import UNPROCESSED +from click._parser import _split_opt from click._utils import UNSET -from click.parser import _split_opt from click.testing import CliRunner From 9016a2b6766da05538b22f44ca3d82b863024676 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Wed, 18 Nov 2026 23:58:59 -0800 Subject: [PATCH 08/18] Factor command parser into function. Unwind circular imports a bit. --- src/click/_base_utils.py | 13 ++ src/click/_parser.py | 360 ++++++++++++++++++++++++++++++++++++++- src/click/core.py | 343 +------------------------------------ src/click/formatting.py | 2 +- tests/test_options.py | 2 +- 5 files changed, 370 insertions(+), 350 deletions(-) create mode 100644 src/click/_base_utils.py diff --git a/src/click/_base_utils.py b/src/click/_base_utils.py new file mode 100644 index 000000000..e2d42f7ab --- /dev/null +++ b/src/click/_base_utils.py @@ -0,0 +1,13 @@ +# Private utilities that must not import anything else from the package. Keeping +# them dependency-free lets any module use them without creating circular imports. +from __future__ import annotations + + +def _split_opt(opt: str) -> tuple[str, str]: + """Splits an option into a prefix and a value.""" + first = opt[:1] + if first.isalnum(): + return "", opt + if opt[1:2] == first: + return opt[:2], opt[2:] + return first, opt[1:] diff --git a/src/click/_parser.py b/src/click/_parser.py index 9cf5a7e00..98fb0bcc0 100644 --- a/src/click/_parser.py +++ b/src/click/_parser.py @@ -1,11 +1,355 @@ from __future__ import annotations +import typing as t +from collections import defaultdict +from gettext import gettext as _ +from gettext import ngettext -def _split_opt(opt: str) -> tuple[str, str]: - """Splits an option into a prefix and a value.""" - first = opt[:1] - if first.isalnum(): - return "", opt - if opt[1:2] == first: - return opt[:2], opt[2:] - return first, opt[1:] +from ._base_utils import _split_opt +from ._utils import FLAG_NEEDS_VALUE +from ._utils import UNSET +from .exceptions import BadArgumentUsage +from .exceptions import BadOptionUsage +from .exceptions import NoSuchOption +from .exceptions import UsageError + +if t.TYPE_CHECKING: + from .core import Context + from .core import Parameter + + +def _command_parse_args( + ctx: Context, args: list[str], params: list[Parameter] +) -> list[str]: + from .core import Argument + from .core import iter_params_for_processing + from .core import Option + + token_normalize_func = ctx.token_normalize_func + + def normalize(name: str) -> str: + if token_normalize_func is None: + return name + + prefix, name = _split_opt(name) + return f"{prefix}{token_normalize_func(name)}" + + # Map each short and long option flag to their option objects, and collect the + # order of positional arguments. The one and two character prefixes used by + # options are collected to check if a token looks like an option. + opt_prefixes: set[str] = {"-", "--"} + short_opts: dict[str, Option] = {} + long_opts: dict[str, Option] = {} + # Normalized secondary names, for easier comparison during parsing. + secondary_opts: set[str] = set() + arg_params: list[Argument] = [] + # Normalized name to the option, declared spelling, and whether it's a + # secondary name, to detect spellings that only collide after normalizing. + claimed: dict[str, tuple[Option, str, bool]] = {} + + for param in params: + if isinstance(param, Option): + names = [(n, False) for n in param.opts] + + if param.is_bool_flag and param.secondary_opts: + names.extend((n, True) for n in param.secondary_opts) + secondary_opts.update(normalize(n) for n in param.secondary_opts) + + for original, is_secondary in names: + name = normalize(original) + + if name in claimed: + other, other_original, other_is_secondary = claimed[name] + + # An identical spelling is a duplicate declaration, which + # get_params warns about, and the last one keeps winning. + if original != other_original and ( + other is not param or other_is_secondary != is_secondary + ): + raise TypeError( + _( + "The option names {first!r} and {second!r} both" + " normalize to {name!r}. Give them names that" + " stay distinct after 'token_normalize_func'." + ).format(first=other_original, second=original, name=name) + ) + + claimed[name] = (param, original, is_secondary) + prefix, value = _split_opt(name) + opt_prefixes.add(prefix[0]) + + if len(prefix) == 1 and len(value) == 1: + # -a is a short opt + short_opts[name] = param + else: + # --a is a long opt, -ab is a long opt with a short prefix + opt_prefixes.add(prefix) + long_opts[name] = param + + elif isinstance(param, Argument): + arg_params.append(param) + + def looks_like_opt(token: str) -> bool: + return len(token) > 1 and token[:1] in opt_prefixes + + def flag_value(opt: Option, name: str) -> t.Any: + if opt.count: + # Each occurrence records the running count, the last one is used. + return len(values[opt.name]) + 1 + + if opt.is_bool_flag and opt.secondary_opts: + return name not in secondary_opts + + return opt.flag_activation_value + + # Map parameter names to collected values. + values: defaultdict[str, list[t.Any]] = defaultdict(list) + # Track what order parameters were seen. + param_order: list[Parameter] = [] + # After mapping arguments to values, any extra values will still be here. + rest: list[str] = [] + # Track what the parser should do with the current token. + lf_any = 0 + lf_value_or_opt = 1 + lf_value = 2 + looking_for = lf_any + # Tracks the current option that needs a value. + looking_opt: Option | None = None + looking_opt_name: str | None = None + # Treat tokens as a stack, with the first token at the top. + tokens = list(reversed(args)) + + try: + while tokens: + token = tokens.pop() + + if looking_for == lf_any: + if token == "--": + # All tokens after -- are considered arguments. + rest.extend(reversed(tokens)) + tokens.clear() + elif looks_like_opt(token): + original_name, long_sep, value = token.partition("=") + name = normalize(original_name) + + if name in long_opts: + # any prefix, matching long opt + opt = long_opts[name] + param_order.append(opt) + takes_value = not (opt.is_flag or opt.count) + + if long_sep: + # key=value, only valid if the option takes a value + if not takes_value: + message = _( + "Option {name!r} does not take a value." + ).format(name=original_name) + raise BadOptionUsage(original_name, message, ctx=ctx) + + tokens.append(value) + looking_opt = opt + looking_opt_name = original_name + looking_for = lf_value + elif not takes_value: + # no attached value, and no value needed + values[opt.name].append(flag_value(opt, name)) + else: + # no attached value, and a value may be needed + looking_opt = opt + looking_opt_name = original_name + + if opt._flag_needs_value: + looking_for = lf_value_or_opt + else: + looking_for = lf_value + elif token[:2] in opt_prefixes: + # long prefix, no matching long opt + if not ctx.ignore_unknown_options: + raise NoSuchOption( + original_name, possibilities=long_opts, ctx=ctx + ) + + rest.append(token) + else: + # short prefix, try short opts + prefix = token[0] + chars = token[1:] + unmatched = [] + + for i, c in enumerate(chars, 1): + original_name = f"{prefix}{c}" + name = normalize(original_name) + + if name not in short_opts: + if not ctx.ignore_unknown_options: + raise NoSuchOption(name, ctx=ctx) + + unmatched.append(c) + continue + + opt = short_opts[name] + param_order.append(opt) + + if opt.is_flag or opt.count: + # Record the flag, then continue trying short opts. + values[opt.name].append(flag_value(opt, name)) + continue + + # Not a flag, stop trying short options and begin + # looking for values. + looking_opt = opt + looking_opt_name = original_name + value = chars[i:] + + if value: + # Use any remaining chars as a value. + tokens.append(value) + looking_for = lf_value + elif opt._flag_needs_value: + looking_for = lf_value_or_opt + else: + looking_for = lf_value + + break + + if unmatched: + # If unknown options are allowed, add any unused chars + # back as a single name with the same prefix. + rest.append(f"{prefix}{''.join(unmatched)}") + else: + # an argument + rest.append(token) + + if not ctx.allow_interspersed_args: + # If interspersed isn't allowed, all remaining + # tokens are considered arguments. + rest.extend(reversed(tokens)) + tokens.clear() + elif looking_for == lf_value_or_opt: + # The current opt optionally takes a value. Look at the + # token then put it back. + assert looking_opt is not None + tokens.append(token) + + if (looking_opt.nargs == 1 and looks_like_opt(token)) or len( + tokens + ) < looking_opt.nargs: + # Next token is an opt, or there aren't enough tokens left. + # Mark the current opt as needing a value, handled during + # processing. + values[looking_opt.name].append(FLAG_NEEDS_VALUE) + looking_opt = looking_opt_name = None + looking_for = lf_any + else: + # Next token will be used as a value. + looking_for = lf_value + elif looking_for == lf_value: + # The current opt requires at least one value. + assert looking_opt is not None and looking_opt_name is not None + + if looking_opt.nargs == 1: + # Exactly one value required + values[looking_opt.name].append(token) + else: + # More than one value required + need_n = looking_opt.nargs - 1 + + if len(tokens) < need_n: + message = ngettext( + "Option {name!r} requires {nargs} values but 1 was given.", + "Option {name!r} requires {nargs} values" + " but {len} were given.", + len(tokens) + 1, + ).format( + name=looking_opt_name, + nargs=looking_opt.nargs, + len=len(tokens) + 1, + ) + raise BadOptionUsage(looking_opt_name, message, ctx=ctx) + + values[looking_opt.name].append( + (token, *reversed(tokens[-need_n:])) + ) + del tokens[-need_n:] + + looking_opt = looking_opt_name = None + looking_for = lf_any + + if looking_for == lf_value_or_opt: + # No more tokens, mark the current opt to get a value later. + assert looking_opt is not None + values[looking_opt.name].append(FLAG_NEEDS_VALUE) + elif looking_for == lf_value: + # No more tokens, but the current opt still required a value. + assert looking_opt is not None and looking_opt_name is not None + message = ngettext( + "Option {name!r} requires a value.", + "Option {name!r} requires {nargs} values.", + looking_opt.nargs, + ).format(name=looking_opt_name, nargs=looking_opt.nargs) + raise BadOptionUsage(looking_opt_name, message, ctx=ctx) + + # Treat args as a stack, with the first at the top. + arg_params.reverse() + + while arg_params: + arg = arg_params.pop() + param_order.append(arg) + + # Missing values aren't recorded, so the value can come from an env + # var or default, or be reported as missing during processing. + if arg.nargs == -1: + need_n = sum(p.nargs for p in arg_params if p.nargs > 0) + + if need_n: + buffer = rest[:-need_n] + rest = rest[-need_n:] + else: + buffer = rest + rest = [] + + if buffer: + values[arg.name].append(tuple(buffer)) + elif arg.nargs == 1: + if rest: + values[arg.name].append(rest.pop(0)) + elif len(rest) >= arg.nargs: + values[arg.name].append(tuple(rest[: arg.nargs])) + rest = rest[arg.nargs :] + elif rest: + message = ngettext( + "Argument {name!r} requires {nargs} values but 1 was given.", + "Argument {name!r} requires {nargs} values but {len} were given.", + len(rest), + ).format(name=arg.make_metavar(ctx), nargs=arg.nargs, len=len(rest)) + raise BadArgumentUsage(message, ctx=ctx) + except UsageError: + if not ctx.resilient_parsing: + raise + + args = rest + + for param in iter_params_for_processing(param_order, params): + args = param.handle_parse_result(ctx, values, args)[1] + + # We now have all parameters' values into `ctx.params`, but the data may contain + # the `UNSET` sentinel. + # Convert `UNSET` to `None` to ensure that the user doesn't see `UNSET`. + # + # Waiting until after the initial parse to convert allows us to treat `UNSET` + # more like a missing value when multiple params use the same name. + for name, value in ctx.params.items(): + if value is UNSET: + ctx.params[name] = None + + if args and not ctx.allow_extra_args and not ctx.resilient_parsing: + message = ngettext( + "Got unexpected extra argument ({args})", + "Got unexpected extra arguments ({args})", + len(args), + ).format(args=" ".join(args)) + raise BadArgumentUsage(message, ctx=ctx) + + ctx.args = args + ctx._opt_prefixes.update(opt_prefixes) + return args diff --git a/src/click/core.py b/src/click/core.py index 01270cfdf..79f65bd9e 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -11,7 +11,6 @@ from abc import abstractmethod from collections import abc from collections import Counter -from collections import defaultdict from contextlib import AbstractContextManager from contextlib import contextmanager from contextlib import ExitStack @@ -23,19 +22,17 @@ from types import TracebackType from . import types -from ._parser import _split_opt +from ._base_utils import _split_opt +from ._parser import _command_parse_args from ._utils import FLAG_NEEDS_VALUE from ._utils import UNSET from .exceptions import Abort -from .exceptions import BadArgumentUsage -from .exceptions import BadOptionUsage from .exceptions import BadParameter from .exceptions import ClickException from .exceptions import Exit from .exceptions import MissingParameter from .exceptions import NoArgsIsHelpError from .exceptions import NoSuchCommand -from .exceptions import NoSuchOption from .exceptions import UsageError from .formatting import HelpFormatter from .formatting import join_options @@ -1380,341 +1377,7 @@ def parse_args(self, ctx: Context, args: list[str]) -> list[str]: if not args and self.no_args_is_help and not ctx.resilient_parsing: raise NoArgsIsHelpError(ctx) - token_normalize_func = ctx.token_normalize_func - - def normalize(name: str) -> str: - if token_normalize_func is None: - return name - - prefix, name = _split_opt(name) - return f"{prefix}{token_normalize_func(name)}" - - params = self.get_params(ctx) - # Map each short and long option flag to their option objects, and collect the - # order of positional arguments. The one and two character prefixes used by - # options are collected to check if a token looks like an option. - opt_prefixes: set[str] = {"-", "--"} - short_opts: dict[str, Option] = {} - long_opts: dict[str, Option] = {} - # Normalized secondary names, for easier comparison during parsing. - secondary_opts: set[str] = set() - arg_params: list[Argument] = [] - # Normalized name to the option, declared spelling, and whether it's a - # secondary name, to detect spellings that only collide after normalizing. - claimed: dict[str, tuple[Option, str, bool]] = {} - - for param in params: - if isinstance(param, Option): - names = [(n, False) for n in param.opts] - - if param.is_bool_flag and param.secondary_opts: - names.extend((n, True) for n in param.secondary_opts) - secondary_opts.update(normalize(n) for n in param.secondary_opts) - - for original, is_secondary in names: - name = normalize(original) - - if name in claimed: - other, other_original, other_is_secondary = claimed[name] - - # An identical spelling is a duplicate declaration, which - # get_params warns about, and the last one keeps winning. - if original != other_original and ( - other is not param or other_is_secondary != is_secondary - ): - raise TypeError( - _( - "The option names {first!r} and {second!r} both" - " normalize to {name!r}. Give them names that" - " stay distinct after 'token_normalize_func'." - ).format( - first=other_original, second=original, name=name - ) - ) - - claimed[name] = (param, original, is_secondary) - prefix, value = _split_opt(name) - opt_prefixes.add(prefix[0]) - - if len(prefix) == 1 and len(value) == 1: - # -a is a short opt - short_opts[name] = param - else: - # --a is a long opt, -ab is a long opt with a short prefix - opt_prefixes.add(prefix) - long_opts[name] = param - - elif isinstance(param, Argument): - arg_params.append(param) - - def looks_like_opt(token: str) -> bool: - return len(token) > 1 and token[:1] in opt_prefixes - - def flag_value(opt: Option, name: str) -> t.Any: - if opt.count: - # Each occurrence records the running count, the last one is used. - return len(values[opt.name]) + 1 - - if opt.is_bool_flag and opt.secondary_opts: - return name not in secondary_opts - - return opt.flag_activation_value - - # Map parameter names to collected values. - values: defaultdict[str, list[t.Any]] = defaultdict(list) - # Track what order parameters were seen. - param_order: list[Parameter] = [] - # After mapping arguments to values, any extra values will still be here. - rest: list[str] = [] - # Track what the parser should do with the current token. - lf_any = 0 - lf_value_or_opt = 1 - lf_value = 2 - looking_for = lf_any - # Tracks the current option that needs a value. - looking_opt: Option | None = None - looking_opt_name: str | None = None - # Treat tokens as a stack, with the first token at the top. - tokens = list(reversed(args)) - - try: - while tokens: - token = tokens.pop() - - if looking_for == lf_any: - if token == "--": - # All tokens after -- are considered arguments. - rest.extend(reversed(tokens)) - tokens.clear() - elif looks_like_opt(token): - original_name, long_sep, value = token.partition("=") - name = normalize(original_name) - - if name in long_opts: - # any prefix, matching long opt - opt = long_opts[name] - param_order.append(opt) - takes_value = not (opt.is_flag or opt.count) - - if long_sep: - # key=value, only valid if the option takes a value - if not takes_value: - message = _( - "Option {name!r} does not take a value." - ).format(name=original_name) - raise BadOptionUsage( - original_name, message, ctx=ctx - ) - - tokens.append(value) - looking_opt = opt - looking_opt_name = original_name - looking_for = lf_value - elif not takes_value: - # no attached value, and no value needed - values[opt.name].append(flag_value(opt, name)) - else: - # no attached value, and a value may be needed - looking_opt = opt - looking_opt_name = original_name - - if opt._flag_needs_value: - looking_for = lf_value_or_opt - else: - looking_for = lf_value - elif token[:2] in opt_prefixes: - # long prefix, no matching long opt - if not ctx.ignore_unknown_options: - raise NoSuchOption( - original_name, possibilities=long_opts, ctx=ctx - ) - - rest.append(token) - else: - # short prefix, try short opts - prefix = token[0] - chars = token[1:] - unmatched = [] - - for i, c in enumerate(chars, 1): - original_name = f"{prefix}{c}" - name = normalize(original_name) - - if name not in short_opts: - if not ctx.ignore_unknown_options: - raise NoSuchOption(name, ctx=ctx) - - unmatched.append(c) - continue - - opt = short_opts[name] - param_order.append(opt) - - if opt.is_flag or opt.count: - # Record the flag, then continue trying short opts. - values[opt.name].append(flag_value(opt, name)) - continue - - # Not a flag, stop trying short options and begin - # looking for values. - looking_opt = opt - looking_opt_name = original_name - value = chars[i:] - - if value: - # Use any remaining chars as a value. - tokens.append(value) - looking_for = lf_value - elif opt._flag_needs_value: - looking_for = lf_value_or_opt - else: - looking_for = lf_value - - break - - if unmatched: - # If unknown options are allowed, add any unused chars - # back as a single name with the same prefix. - rest.append(f"{prefix}{''.join(unmatched)}") - else: - # an argument - rest.append(token) - - if not ctx.allow_interspersed_args: - # If interspersed isn't allowed, all remaining - # tokens are considered arguments. - rest.extend(reversed(tokens)) - tokens.clear() - elif looking_for == lf_value_or_opt: - # The current opt optionally takes a value. Look at the - # token then put it back. - assert looking_opt is not None - tokens.append(token) - - if (looking_opt.nargs == 1 and looks_like_opt(token)) or len( - tokens - ) < looking_opt.nargs: - # Next token is an opt, or there aren't enough tokens left. - # Mark the current opt as needing a value, handled during - # processing. - values[looking_opt.name].append(FLAG_NEEDS_VALUE) - looking_opt = looking_opt_name = None - looking_for = lf_any - else: - # Next token will be used as a value. - looking_for = lf_value - elif looking_for == lf_value: - # The current opt requires at least one value. - assert looking_opt is not None and looking_opt_name is not None - - if looking_opt.nargs == 1: - # Exactly one value required - values[looking_opt.name].append(token) - else: - # More than one value required - need_n = looking_opt.nargs - 1 - - if len(tokens) < need_n: - message = ngettext( - "Option {name!r} requires {nargs} values" - " but 1 was given.", - "Option {name!r} requires {nargs} values" - " but {len} were given.", - len(tokens) + 1, - ).format( - name=looking_opt_name, - nargs=looking_opt.nargs, - len=len(tokens) + 1, - ) - raise BadOptionUsage(looking_opt_name, message, ctx=ctx) - - values[looking_opt.name].append( - (token, *reversed(tokens[-need_n:])) - ) - del tokens[-need_n:] - - looking_opt = looking_opt_name = None - looking_for = lf_any - - if looking_for == lf_value_or_opt: - # No more tokens, mark the current opt to get a value later. - assert looking_opt is not None - values[looking_opt.name].append(FLAG_NEEDS_VALUE) - elif looking_for == lf_value: - # No more tokens, but the current opt still required a value. - assert looking_opt is not None and looking_opt_name is not None - message = ngettext( - "Option {name!r} requires a value.", - "Option {name!r} requires {nargs} values.", - looking_opt.nargs, - ).format(name=looking_opt_name, nargs=looking_opt.nargs) - raise BadOptionUsage(looking_opt_name, message, ctx=ctx) - - # Treat args as a stack, with the first at the top. - arg_params.reverse() - - while arg_params: - arg = arg_params.pop() - param_order.append(arg) - - # Missing values aren't recorded, so the value can come from an env - # var or default, or be reported as missing during processing. - if arg.nargs == -1: - need_n = sum(p.nargs for p in arg_params if p.nargs > 0) - - if need_n: - buffer = rest[:-need_n] - rest = rest[-need_n:] - else: - buffer = rest - rest = [] - - if buffer: - values[arg.name].append(tuple(buffer)) - elif arg.nargs == 1: - if rest: - values[arg.name].append(rest.pop(0)) - elif len(rest) >= arg.nargs: - values[arg.name].append(tuple(rest[: arg.nargs])) - rest = rest[arg.nargs :] - elif rest: - message = ngettext( - "Argument {name!r} requires {nargs} values but 1 was given.", - "Argument {name!r} requires {nargs} values" - " but {len} were given.", - len(rest), - ).format(name=arg.make_metavar(ctx), nargs=arg.nargs, len=len(rest)) - raise BadArgumentUsage(message, ctx=ctx) - except UsageError: - if not ctx.resilient_parsing: - raise - - args = rest - - for param in iter_params_for_processing(param_order, params): - args = param.handle_parse_result(ctx, values, args)[1] - - # We now have all parameters' values into `ctx.params`, but the data may contain - # the `UNSET` sentinel. - # Convert `UNSET` to `None` to ensure that the user doesn't see `UNSET`. - # - # Waiting until after the initial parse to convert allows us to treat `UNSET` - # more like a missing value when multiple params use the same name. - for name, value in ctx.params.items(): - if value is UNSET: - ctx.params[name] = None - - if args and not ctx.allow_extra_args and not ctx.resilient_parsing: - message = ngettext( - "Got unexpected extra argument ({args})", - "Got unexpected extra arguments ({args})", - len(args), - ).format(args=" ".join(args)) - raise BadArgumentUsage(message, ctx=ctx) - - ctx.args = args - ctx._opt_prefixes.update(opt_prefixes) - return args + return _command_parse_args(ctx, args, self.get_params(ctx)) def invoke(self, ctx: Context) -> t.Any: """Given a context, this invokes the attached callback (if it exists) diff --git a/src/click/formatting.py b/src/click/formatting.py index 3da541a2d..bc45d51d0 100644 --- a/src/click/formatting.py +++ b/src/click/formatting.py @@ -4,8 +4,8 @@ from contextlib import contextmanager from gettext import gettext as _ +from ._base_utils import _split_opt from ._compat import term_len -from ._parser import _split_opt # Can force a width. This is used by the test system FORCED_WIDTH: int | None = None diff --git a/tests/test_options.py b/tests/test_options.py index 2815a86ac..649e21dec 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -13,7 +13,7 @@ import click from click import Option from click import UNPROCESSED -from click._parser import _split_opt +from click._base_utils import _split_opt from click._utils import UNSET from click.testing import CliRunner From 5fa30a17220f50dee33f5d3d3319376cfa7222a2 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:18:59 -0800 Subject: [PATCH 09/18] Unwind factor into own function due to circular imports. --- src/click/_parser.py | 354 ------------------------------------------- src/click/core.py | 341 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 339 insertions(+), 356 deletions(-) diff --git a/src/click/_parser.py b/src/click/_parser.py index 98fb0bcc0..9d48db4f9 100644 --- a/src/click/_parser.py +++ b/src/click/_parser.py @@ -1,355 +1 @@ from __future__ import annotations - -import typing as t -from collections import defaultdict -from gettext import gettext as _ -from gettext import ngettext - -from ._base_utils import _split_opt -from ._utils import FLAG_NEEDS_VALUE -from ._utils import UNSET -from .exceptions import BadArgumentUsage -from .exceptions import BadOptionUsage -from .exceptions import NoSuchOption -from .exceptions import UsageError - -if t.TYPE_CHECKING: - from .core import Context - from .core import Parameter - - -def _command_parse_args( - ctx: Context, args: list[str], params: list[Parameter] -) -> list[str]: - from .core import Argument - from .core import iter_params_for_processing - from .core import Option - - token_normalize_func = ctx.token_normalize_func - - def normalize(name: str) -> str: - if token_normalize_func is None: - return name - - prefix, name = _split_opt(name) - return f"{prefix}{token_normalize_func(name)}" - - # Map each short and long option flag to their option objects, and collect the - # order of positional arguments. The one and two character prefixes used by - # options are collected to check if a token looks like an option. - opt_prefixes: set[str] = {"-", "--"} - short_opts: dict[str, Option] = {} - long_opts: dict[str, Option] = {} - # Normalized secondary names, for easier comparison during parsing. - secondary_opts: set[str] = set() - arg_params: list[Argument] = [] - # Normalized name to the option, declared spelling, and whether it's a - # secondary name, to detect spellings that only collide after normalizing. - claimed: dict[str, tuple[Option, str, bool]] = {} - - for param in params: - if isinstance(param, Option): - names = [(n, False) for n in param.opts] - - if param.is_bool_flag and param.secondary_opts: - names.extend((n, True) for n in param.secondary_opts) - secondary_opts.update(normalize(n) for n in param.secondary_opts) - - for original, is_secondary in names: - name = normalize(original) - - if name in claimed: - other, other_original, other_is_secondary = claimed[name] - - # An identical spelling is a duplicate declaration, which - # get_params warns about, and the last one keeps winning. - if original != other_original and ( - other is not param or other_is_secondary != is_secondary - ): - raise TypeError( - _( - "The option names {first!r} and {second!r} both" - " normalize to {name!r}. Give them names that" - " stay distinct after 'token_normalize_func'." - ).format(first=other_original, second=original, name=name) - ) - - claimed[name] = (param, original, is_secondary) - prefix, value = _split_opt(name) - opt_prefixes.add(prefix[0]) - - if len(prefix) == 1 and len(value) == 1: - # -a is a short opt - short_opts[name] = param - else: - # --a is a long opt, -ab is a long opt with a short prefix - opt_prefixes.add(prefix) - long_opts[name] = param - - elif isinstance(param, Argument): - arg_params.append(param) - - def looks_like_opt(token: str) -> bool: - return len(token) > 1 and token[:1] in opt_prefixes - - def flag_value(opt: Option, name: str) -> t.Any: - if opt.count: - # Each occurrence records the running count, the last one is used. - return len(values[opt.name]) + 1 - - if opt.is_bool_flag and opt.secondary_opts: - return name not in secondary_opts - - return opt.flag_activation_value - - # Map parameter names to collected values. - values: defaultdict[str, list[t.Any]] = defaultdict(list) - # Track what order parameters were seen. - param_order: list[Parameter] = [] - # After mapping arguments to values, any extra values will still be here. - rest: list[str] = [] - # Track what the parser should do with the current token. - lf_any = 0 - lf_value_or_opt = 1 - lf_value = 2 - looking_for = lf_any - # Tracks the current option that needs a value. - looking_opt: Option | None = None - looking_opt_name: str | None = None - # Treat tokens as a stack, with the first token at the top. - tokens = list(reversed(args)) - - try: - while tokens: - token = tokens.pop() - - if looking_for == lf_any: - if token == "--": - # All tokens after -- are considered arguments. - rest.extend(reversed(tokens)) - tokens.clear() - elif looks_like_opt(token): - original_name, long_sep, value = token.partition("=") - name = normalize(original_name) - - if name in long_opts: - # any prefix, matching long opt - opt = long_opts[name] - param_order.append(opt) - takes_value = not (opt.is_flag or opt.count) - - if long_sep: - # key=value, only valid if the option takes a value - if not takes_value: - message = _( - "Option {name!r} does not take a value." - ).format(name=original_name) - raise BadOptionUsage(original_name, message, ctx=ctx) - - tokens.append(value) - looking_opt = opt - looking_opt_name = original_name - looking_for = lf_value - elif not takes_value: - # no attached value, and no value needed - values[opt.name].append(flag_value(opt, name)) - else: - # no attached value, and a value may be needed - looking_opt = opt - looking_opt_name = original_name - - if opt._flag_needs_value: - looking_for = lf_value_or_opt - else: - looking_for = lf_value - elif token[:2] in opt_prefixes: - # long prefix, no matching long opt - if not ctx.ignore_unknown_options: - raise NoSuchOption( - original_name, possibilities=long_opts, ctx=ctx - ) - - rest.append(token) - else: - # short prefix, try short opts - prefix = token[0] - chars = token[1:] - unmatched = [] - - for i, c in enumerate(chars, 1): - original_name = f"{prefix}{c}" - name = normalize(original_name) - - if name not in short_opts: - if not ctx.ignore_unknown_options: - raise NoSuchOption(name, ctx=ctx) - - unmatched.append(c) - continue - - opt = short_opts[name] - param_order.append(opt) - - if opt.is_flag or opt.count: - # Record the flag, then continue trying short opts. - values[opt.name].append(flag_value(opt, name)) - continue - - # Not a flag, stop trying short options and begin - # looking for values. - looking_opt = opt - looking_opt_name = original_name - value = chars[i:] - - if value: - # Use any remaining chars as a value. - tokens.append(value) - looking_for = lf_value - elif opt._flag_needs_value: - looking_for = lf_value_or_opt - else: - looking_for = lf_value - - break - - if unmatched: - # If unknown options are allowed, add any unused chars - # back as a single name with the same prefix. - rest.append(f"{prefix}{''.join(unmatched)}") - else: - # an argument - rest.append(token) - - if not ctx.allow_interspersed_args: - # If interspersed isn't allowed, all remaining - # tokens are considered arguments. - rest.extend(reversed(tokens)) - tokens.clear() - elif looking_for == lf_value_or_opt: - # The current opt optionally takes a value. Look at the - # token then put it back. - assert looking_opt is not None - tokens.append(token) - - if (looking_opt.nargs == 1 and looks_like_opt(token)) or len( - tokens - ) < looking_opt.nargs: - # Next token is an opt, or there aren't enough tokens left. - # Mark the current opt as needing a value, handled during - # processing. - values[looking_opt.name].append(FLAG_NEEDS_VALUE) - looking_opt = looking_opt_name = None - looking_for = lf_any - else: - # Next token will be used as a value. - looking_for = lf_value - elif looking_for == lf_value: - # The current opt requires at least one value. - assert looking_opt is not None and looking_opt_name is not None - - if looking_opt.nargs == 1: - # Exactly one value required - values[looking_opt.name].append(token) - else: - # More than one value required - need_n = looking_opt.nargs - 1 - - if len(tokens) < need_n: - message = ngettext( - "Option {name!r} requires {nargs} values but 1 was given.", - "Option {name!r} requires {nargs} values" - " but {len} were given.", - len(tokens) + 1, - ).format( - name=looking_opt_name, - nargs=looking_opt.nargs, - len=len(tokens) + 1, - ) - raise BadOptionUsage(looking_opt_name, message, ctx=ctx) - - values[looking_opt.name].append( - (token, *reversed(tokens[-need_n:])) - ) - del tokens[-need_n:] - - looking_opt = looking_opt_name = None - looking_for = lf_any - - if looking_for == lf_value_or_opt: - # No more tokens, mark the current opt to get a value later. - assert looking_opt is not None - values[looking_opt.name].append(FLAG_NEEDS_VALUE) - elif looking_for == lf_value: - # No more tokens, but the current opt still required a value. - assert looking_opt is not None and looking_opt_name is not None - message = ngettext( - "Option {name!r} requires a value.", - "Option {name!r} requires {nargs} values.", - looking_opt.nargs, - ).format(name=looking_opt_name, nargs=looking_opt.nargs) - raise BadOptionUsage(looking_opt_name, message, ctx=ctx) - - # Treat args as a stack, with the first at the top. - arg_params.reverse() - - while arg_params: - arg = arg_params.pop() - param_order.append(arg) - - # Missing values aren't recorded, so the value can come from an env - # var or default, or be reported as missing during processing. - if arg.nargs == -1: - need_n = sum(p.nargs for p in arg_params if p.nargs > 0) - - if need_n: - buffer = rest[:-need_n] - rest = rest[-need_n:] - else: - buffer = rest - rest = [] - - if buffer: - values[arg.name].append(tuple(buffer)) - elif arg.nargs == 1: - if rest: - values[arg.name].append(rest.pop(0)) - elif len(rest) >= arg.nargs: - values[arg.name].append(tuple(rest[: arg.nargs])) - rest = rest[arg.nargs :] - elif rest: - message = ngettext( - "Argument {name!r} requires {nargs} values but 1 was given.", - "Argument {name!r} requires {nargs} values but {len} were given.", - len(rest), - ).format(name=arg.make_metavar(ctx), nargs=arg.nargs, len=len(rest)) - raise BadArgumentUsage(message, ctx=ctx) - except UsageError: - if not ctx.resilient_parsing: - raise - - args = rest - - for param in iter_params_for_processing(param_order, params): - args = param.handle_parse_result(ctx, values, args)[1] - - # We now have all parameters' values into `ctx.params`, but the data may contain - # the `UNSET` sentinel. - # Convert `UNSET` to `None` to ensure that the user doesn't see `UNSET`. - # - # Waiting until after the initial parse to convert allows us to treat `UNSET` - # more like a missing value when multiple params use the same name. - for name, value in ctx.params.items(): - if value is UNSET: - ctx.params[name] = None - - if args and not ctx.allow_extra_args and not ctx.resilient_parsing: - message = ngettext( - "Got unexpected extra argument ({args})", - "Got unexpected extra arguments ({args})", - len(args), - ).format(args=" ".join(args)) - raise BadArgumentUsage(message, ctx=ctx) - - ctx.args = args - ctx._opt_prefixes.update(opt_prefixes) - return args diff --git a/src/click/core.py b/src/click/core.py index 79f65bd9e..5ea5f5de3 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -11,6 +11,7 @@ from abc import abstractmethod from collections import abc from collections import Counter +from collections import defaultdict from contextlib import AbstractContextManager from contextlib import contextmanager from contextlib import ExitStack @@ -23,16 +24,18 @@ from . import types from ._base_utils import _split_opt -from ._parser import _command_parse_args from ._utils import FLAG_NEEDS_VALUE from ._utils import UNSET from .exceptions import Abort +from .exceptions import BadArgumentUsage +from .exceptions import BadOptionUsage from .exceptions import BadParameter from .exceptions import ClickException from .exceptions import Exit from .exceptions import MissingParameter from .exceptions import NoArgsIsHelpError from .exceptions import NoSuchCommand +from .exceptions import NoSuchOption from .exceptions import UsageError from .formatting import HelpFormatter from .formatting import join_options @@ -1377,7 +1380,341 @@ def parse_args(self, ctx: Context, args: list[str]) -> list[str]: if not args and self.no_args_is_help and not ctx.resilient_parsing: raise NoArgsIsHelpError(ctx) - return _command_parse_args(ctx, args, self.get_params(ctx)) + token_normalize_func = ctx.token_normalize_func + + def normalize(name: str) -> str: + if token_normalize_func is None: + return name + + prefix, name = _split_opt(name) + return f"{prefix}{token_normalize_func(name)}" + + params = self.get_params(ctx) + # Map each short and long option flag to their option objects, and collect the + # order of positional arguments. The one and two character prefixes used by + # options are collected to check if a token looks like an option. + opt_prefixes: set[str] = {"-", "--"} + short_opts: dict[str, Option] = {} + long_opts: dict[str, Option] = {} + # Normalized secondary names, for easier comparison during parsing. + secondary_opts: set[str] = set() + arg_params: list[Argument] = [] + # Normalized name to the option, declared spelling, and whether it's a + # secondary name, to detect spellings that only collide after normalizing. + claimed: dict[str, tuple[Option, str, bool]] = {} + + for param in params: + if isinstance(param, Option): + names = [(n, False) for n in param.opts] + + if param.is_bool_flag and param.secondary_opts: + names.extend((n, True) for n in param.secondary_opts) + secondary_opts.update(normalize(n) for n in param.secondary_opts) + + for original, is_secondary in names: + name = normalize(original) + + if name in claimed: + other, other_original, other_is_secondary = claimed[name] + + # An identical spelling is a duplicate declaration, which + # get_params warns about, and the last one keeps winning. + if original != other_original and ( + other is not param or other_is_secondary != is_secondary + ): + raise TypeError( + _( + "The option names {first!r} and {second!r} both" + " normalize to {name!r}. Give them names that" + " stay distinct after 'token_normalize_func'." + ).format( + first=other_original, second=original, name=name + ) + ) + + claimed[name] = (param, original, is_secondary) + prefix, value = _split_opt(name) + opt_prefixes.add(prefix[0]) + + if len(prefix) == 1 and len(value) == 1: + # -a is a short opt + short_opts[name] = param + else: + # --a is a long opt, -ab is a long opt with a short prefix + opt_prefixes.add(prefix) + long_opts[name] = param + + elif isinstance(param, Argument): + arg_params.append(param) + + def looks_like_opt(token: str) -> bool: + return len(token) > 1 and token[:1] in opt_prefixes + + def flag_value(opt: Option, name: str) -> t.Any: + if opt.count: + # Each occurrence records the running count, the last one is used. + return len(values[opt.name]) + 1 + + if opt.is_bool_flag and opt.secondary_opts: + return name not in secondary_opts + + return opt.flag_activation_value + + # Map parameter names to collected values. + values: defaultdict[str, list[t.Any]] = defaultdict(list) + # Track what order parameters were seen. + param_order: list[Parameter] = [] + # After mapping arguments to values, any extra values will still be here. + rest: list[str] = [] + # Track what the parser should do with the current token. + lf_any = 0 + lf_value_or_opt = 1 + lf_value = 2 + looking_for = lf_any + # Tracks the current option that needs a value. + looking_opt: Option | None = None + looking_opt_name: str | None = None + # Treat tokens as a stack, with the first token at the top. + tokens = list(reversed(args)) + + try: + while tokens: + token = tokens.pop() + + if looking_for == lf_any: + if token == "--": + # All tokens after -- are considered arguments. + rest.extend(reversed(tokens)) + tokens.clear() + elif looks_like_opt(token): + original_name, long_sep, value = token.partition("=") + name = normalize(original_name) + + if name in long_opts: + # any prefix, matching long opt + opt = long_opts[name] + param_order.append(opt) + takes_value = not (opt.is_flag or opt.count) + + if long_sep: + # key=value, only valid if the option takes a value + if not takes_value: + message = _( + "Option {name!r} does not take a value." + ).format(name=original_name) + raise BadOptionUsage( + original_name, message, ctx=ctx + ) + + tokens.append(value) + looking_opt = opt + looking_opt_name = original_name + looking_for = lf_value + elif not takes_value: + # no attached value, and no value needed + values[opt.name].append(flag_value(opt, name)) + else: + # no attached value, and a value may be needed + looking_opt = opt + looking_opt_name = original_name + + if opt._flag_needs_value: + looking_for = lf_value_or_opt + else: + looking_for = lf_value + elif token[:2] in opt_prefixes: + # long prefix, no matching long opt + if not ctx.ignore_unknown_options: + raise NoSuchOption( + original_name, possibilities=long_opts, ctx=ctx + ) + + rest.append(token) + else: + # short prefix, try short opts + prefix = token[0] + chars = token[1:] + unmatched = [] + + for i, c in enumerate(chars, 1): + original_name = f"{prefix}{c}" + name = normalize(original_name) + + if name not in short_opts: + if not ctx.ignore_unknown_options: + raise NoSuchOption(name, ctx=ctx) + + unmatched.append(c) + continue + + opt = short_opts[name] + param_order.append(opt) + + if opt.is_flag or opt.count: + # Record the flag, then continue trying short opts. + values[opt.name].append(flag_value(opt, name)) + continue + + # Not a flag, stop trying short options and begin + # looking for values. + looking_opt = opt + looking_opt_name = original_name + value = chars[i:] + + if value: + # Use any remaining chars as a value. + tokens.append(value) + looking_for = lf_value + elif opt._flag_needs_value: + looking_for = lf_value_or_opt + else: + looking_for = lf_value + + break + + if unmatched: + # If unknown options are allowed, add any unused chars + # back as a single name with the same prefix. + rest.append(f"{prefix}{''.join(unmatched)}") + else: + # an argument + rest.append(token) + + if not ctx.allow_interspersed_args: + # If interspersed isn't allowed, all remaining + # tokens are considered arguments. + rest.extend(reversed(tokens)) + tokens.clear() + elif looking_for == lf_value_or_opt: + # The current opt optionally takes a value. Look at the + # token then put it back. + assert looking_opt is not None + tokens.append(token) + + if (looking_opt.nargs == 1 and looks_like_opt(token)) or len( + tokens + ) < looking_opt.nargs: + # Next token is an opt, or there aren't enough tokens left. + # Mark the current opt as needing a value, handled during + # processing. + values[looking_opt.name].append(FLAG_NEEDS_VALUE) + looking_opt = looking_opt_name = None + looking_for = lf_any + else: + # Next token will be used as a value. + looking_for = lf_value + elif looking_for == lf_value: + # The current opt requires at least one value. + assert looking_opt is not None and looking_opt_name is not None + + if looking_opt.nargs == 1: + # Exactly one value required + values[looking_opt.name].append(token) + else: + # More than one value required + need_n = looking_opt.nargs - 1 + + if len(tokens) < need_n: + message = ngettext( + "Option {name!r} requires {nargs} values" + " but 1 was given.", + "Option {name!r} requires {nargs} values" + " but {len} were given.", + len(tokens) + 1, + ).format( + name=looking_opt_name, + nargs=looking_opt.nargs, + len=len(tokens) + 1, + ) + raise BadOptionUsage(looking_opt_name, message, ctx=ctx) + + values[looking_opt.name].append( + (token, *reversed(tokens[-need_n:])) + ) + del tokens[-need_n:] + + looking_opt = looking_opt_name = None + looking_for = lf_any + + if looking_for == lf_value_or_opt: + # No more tokens, mark the current opt to get a value later. + assert looking_opt is not None + values[looking_opt.name].append(FLAG_NEEDS_VALUE) + elif looking_for == lf_value: + # No more tokens, but the current opt still required a value. + assert looking_opt is not None and looking_opt_name is not None + message = ngettext( + "Option {name!r} requires a value.", + "Option {name!r} requires {nargs} values.", + looking_opt.nargs, + ).format(name=looking_opt_name, nargs=looking_opt.nargs) + raise BadOptionUsage(looking_opt_name, message, ctx=ctx) + + # Treat args as a stack, with the first at the top. + arg_params.reverse() + + while arg_params: + arg = arg_params.pop() + param_order.append(arg) + + # Missing values aren't recorded, so the value can come from an env + # var or default, or be reported as missing during processing. + if arg.nargs == -1: + need_n = sum(p.nargs for p in arg_params if p.nargs > 0) + + if need_n: + buffer = rest[:-need_n] + rest = rest[-need_n:] + else: + buffer = rest + rest = [] + + if buffer: + values[arg.name].append(tuple(buffer)) + elif arg.nargs == 1: + if rest: + values[arg.name].append(rest.pop(0)) + elif len(rest) >= arg.nargs: + values[arg.name].append(tuple(rest[: arg.nargs])) + rest = rest[arg.nargs :] + elif rest: + message = ngettext( + "Argument {name!r} requires {nargs} values but 1 was given.", + "Argument {name!r} requires {nargs} values" + " but {len} were given.", + len(rest), + ).format(name=arg.make_metavar(ctx), nargs=arg.nargs, len=len(rest)) + raise BadArgumentUsage(message, ctx=ctx) + except UsageError: + if not ctx.resilient_parsing: + raise + + args = rest + + for param in iter_params_for_processing(param_order, params): + args = param.handle_parse_result(ctx, values, args)[1] + + # We now have all parameters' values into `ctx.params`, but the data may contain + # the `UNSET` sentinel. + # Convert `UNSET` to `None` to ensure that the user doesn't see `UNSET`. + # + # Waiting until after the initial parse to convert allows us to treat `UNSET` + # more like a missing value when multiple params use the same name. + for name, value in ctx.params.items(): + if value is UNSET: + ctx.params[name] = None + + if args and not ctx.allow_extra_args and not ctx.resilient_parsing: + message = ngettext( + "Got unexpected extra argument ({args})", + "Got unexpected extra arguments ({args})", + len(args), + ).format(args=" ".join(args)) + raise BadArgumentUsage(message, ctx=ctx) + + ctx.args = args + ctx._opt_prefixes.update(opt_prefixes) + return args def invoke(self, ctx: Context) -> t.Any: """Given a context, this invokes the attached callback (if it exists) From 733b6f7c948d4fce0850e67a7c50943f99abe21c Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:21:52 -0800 Subject: [PATCH 10/18] Make parse args private. --- src/click/core.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/click/core.py b/src/click/core.py index 5ea5f5de3..d354e8425 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -1377,6 +1377,9 @@ def make_context( return ctx def parse_args(self, ctx: Context, args: list[str]) -> list[str]: + return self._parse_args(ctx, args) + + def _parse_args(self, ctx: Context, args: list[str]) -> list[str]: if not args and self.no_args_is_help and not ctx.resilient_parsing: raise NoArgsIsHelpError(ctx) From e08755d07896d9f1bb3841ed1912add26168c56b Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:33:11 -0800 Subject: [PATCH 11/18] Factor build opt tables into method. --- src/click/core.py | 129 ++++++++++++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 56 deletions(-) diff --git a/src/click/core.py b/src/click/core.py index d354e8425..81335ffb1 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -1393,62 +1393,9 @@ def normalize(name: str) -> str: return f"{prefix}{token_normalize_func(name)}" params = self.get_params(ctx) - # Map each short and long option flag to their option objects, and collect the - # order of positional arguments. The one and two character prefixes used by - # options are collected to check if a token looks like an option. - opt_prefixes: set[str] = {"-", "--"} - short_opts: dict[str, Option] = {} - long_opts: dict[str, Option] = {} - # Normalized secondary names, for easier comparison during parsing. - secondary_opts: set[str] = set() - arg_params: list[Argument] = [] - # Normalized name to the option, declared spelling, and whether it's a - # secondary name, to detect spellings that only collide after normalizing. - claimed: dict[str, tuple[Option, str, bool]] = {} - - for param in params: - if isinstance(param, Option): - names = [(n, False) for n in param.opts] - - if param.is_bool_flag and param.secondary_opts: - names.extend((n, True) for n in param.secondary_opts) - secondary_opts.update(normalize(n) for n in param.secondary_opts) - - for original, is_secondary in names: - name = normalize(original) - - if name in claimed: - other, other_original, other_is_secondary = claimed[name] - - # An identical spelling is a duplicate declaration, which - # get_params warns about, and the last one keeps winning. - if original != other_original and ( - other is not param or other_is_secondary != is_secondary - ): - raise TypeError( - _( - "The option names {first!r} and {second!r} both" - " normalize to {name!r}. Give them names that" - " stay distinct after 'token_normalize_func'." - ).format( - first=other_original, second=original, name=name - ) - ) - - claimed[name] = (param, original, is_secondary) - prefix, value = _split_opt(name) - opt_prefixes.add(prefix[0]) - - if len(prefix) == 1 and len(value) == 1: - # -a is a short opt - short_opts[name] = param - else: - # --a is a long opt, -ab is a long opt with a short prefix - opt_prefixes.add(prefix) - long_opts[name] = param - - elif isinstance(param, Argument): - arg_params.append(param) + short_opts, long_opts, secondary_opts, opt_prefixes, arg_params = ( + self._build_opt_tables(params, normalize) + ) def looks_like_opt(token: str) -> bool: return len(token) > 1 and token[:1] in opt_prefixes @@ -1719,6 +1666,76 @@ def flag_value(opt: Option, name: str) -> t.Any: ctx._opt_prefixes.update(opt_prefixes) return args + def _build_opt_tables( + self, params: cabc.Sequence[Parameter], normalize: cabc.Callable[[str], str] + ) -> tuple[ + dict[str, Option], dict[str, Option], set[str], set[str], list[Argument] + ]: + """Map each normalized short and long option name to its option, and collect + the positional arguments in order. + + Returns the short options, long options, normalized secondary names, option + prefixes, and arguments. The one and two character prefixes used by options + are collected to check if a token looks like an option. + + :raise TypeError: Two different option names normalize to the same name. + """ + opt_prefixes: set[str] = {"-", "--"} + short_opts: dict[str, Option] = {} + long_opts: dict[str, Option] = {} + # Normalized secondary names, for easier comparison during parsing. + secondary_opts: set[str] = set() + arg_params: list[Argument] = [] + # Normalized name to the option, declared spelling, and whether it's a + # secondary name, to detect spellings that only collide after normalizing. + claimed: dict[str, tuple[Option, str, bool]] = {} + + for param in params: + if isinstance(param, Option): + names = [(n, False) for n in param.opts] + + if param.is_bool_flag and param.secondary_opts: + names.extend((n, True) for n in param.secondary_opts) + secondary_opts.update(normalize(n) for n in param.secondary_opts) + + for original, is_secondary in names: + name = normalize(original) + + if name in claimed: + other, other_original, other_is_secondary = claimed[name] + + # An identical spelling is a duplicate declaration, which + # get_params warns about, and the last one keeps winning. + if original != other_original and ( + other is not param or other_is_secondary != is_secondary + ): + raise TypeError( + _( + "The option names {first!r} and {second!r} both" + " normalize to {name!r}. Give them names that" + " stay distinct after 'token_normalize_func'." + ).format( + first=other_original, second=original, name=name + ) + ) + + claimed[name] = (param, original, is_secondary) + prefix, value = _split_opt(name) + opt_prefixes.add(prefix[0]) + + if len(prefix) == 1 and len(value) == 1: + # -a is a short opt + short_opts[name] = param + else: + # --a is a long opt, -ab is a long opt with a short prefix + opt_prefixes.add(prefix) + long_opts[name] = param + + elif isinstance(param, Argument): + arg_params.append(param) + + return short_opts, long_opts, secondary_opts, opt_prefixes, arg_params + def invoke(self, ctx: Context) -> t.Any: """Given a context, this invokes the attached callback (if it exists) in the right way. From c12397bcc06f923e45b1779031ea91365f07b19e Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:38:27 -0800 Subject: [PATCH 12/18] Convert _build_opt_tables to static method. --- src/click/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/click/core.py b/src/click/core.py index 81335ffb1..c996325a4 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -1666,8 +1666,9 @@ def flag_value(opt: Option, name: str) -> t.Any: ctx._opt_prefixes.update(opt_prefixes) return args + @staticmethod def _build_opt_tables( - self, params: cabc.Sequence[Parameter], normalize: cabc.Callable[[str], str] + params: cabc.Sequence[Parameter], normalize: cabc.Callable[[str], str] ) -> tuple[ dict[str, Option], dict[str, Option], set[str], set[str], list[Argument] ]: From 0fde8db332b13ea7e9218d895b70ea16ce301930 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:55:09 -0800 Subject: [PATCH 13/18] Factor out assign_args. --- src/click/core.py | 87 +++++++++++++++++++++++++----------------- tests/test_commands.py | 19 +++++++++ 2 files changed, 71 insertions(+), 35 deletions(-) diff --git a/src/click/core.py b/src/click/core.py index c996325a4..59dae4c2d 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -1600,41 +1600,7 @@ def flag_value(opt: Option, name: str) -> t.Any: ).format(name=looking_opt_name, nargs=looking_opt.nargs) raise BadOptionUsage(looking_opt_name, message, ctx=ctx) - # Treat args as a stack, with the first at the top. - arg_params.reverse() - - while arg_params: - arg = arg_params.pop() - param_order.append(arg) - - # Missing values aren't recorded, so the value can come from an env - # var or default, or be reported as missing during processing. - if arg.nargs == -1: - need_n = sum(p.nargs for p in arg_params if p.nargs > 0) - - if need_n: - buffer = rest[:-need_n] - rest = rest[-need_n:] - else: - buffer = rest - rest = [] - - if buffer: - values[arg.name].append(tuple(buffer)) - elif arg.nargs == 1: - if rest: - values[arg.name].append(rest.pop(0)) - elif len(rest) >= arg.nargs: - values[arg.name].append(tuple(rest[: arg.nargs])) - rest = rest[arg.nargs :] - elif rest: - message = ngettext( - "Argument {name!r} requires {nargs} values but 1 was given.", - "Argument {name!r} requires {nargs} values" - " but {len} were given.", - len(rest), - ).format(name=arg.make_metavar(ctx), nargs=arg.nargs, len=len(rest)) - raise BadArgumentUsage(message, ctx=ctx) + self._assign_args(ctx, arg_params, rest, values, param_order) except UsageError: if not ctx.resilient_parsing: raise @@ -1666,6 +1632,57 @@ def flag_value(opt: Option, name: str) -> t.Any: ctx._opt_prefixes.update(opt_prefixes) return args + @staticmethod + def _assign_args( + ctx: Context, + arg_params: list[Argument], + rest: list[str], + values: defaultdict[str, list[t.Any]], + param_order: list[Parameter], + ) -> None: + """Assign the remaining tokens to the positional arguments in order. + + Consumes ``arg_params`` and ``rest`` in place, so that if an error is + raised and ignored for resilient parsing, ``rest`` still holds the + tokens that weren't assigned. + + :raise BadArgumentUsage: An argument has some but not all of its values. + """ + # Treat args as a stack, with the first at the top. + arg_params.reverse() + + while arg_params: + arg = arg_params.pop() + param_order.append(arg) + + # Missing values aren't recorded, so the value can come from an env + # var or default, or be reported as missing during processing. + if arg.nargs == -1: + need_n = sum(p.nargs for p in arg_params if p.nargs > 0) + + if need_n: + buffer = rest[:-need_n] + del rest[:-need_n] + else: + buffer = rest[:] + rest.clear() + + if buffer: + values[arg.name].append(tuple(buffer)) + elif arg.nargs == 1: + if rest: + values[arg.name].append(rest.pop(0)) + elif len(rest) >= arg.nargs: + values[arg.name].append(tuple(rest[: arg.nargs])) + del rest[: arg.nargs] + elif rest: + message = ngettext( + "Argument {name!r} requires {nargs} values but 1 was given.", + "Argument {name!r} requires {nargs} values but {len} were given.", + len(rest), + ).format(name=arg.make_metavar(ctx), nargs=arg.nargs, len=len(rest)) + raise BadArgumentUsage(message, ctx=ctx) + @staticmethod def _build_opt_tables( params: cabc.Sequence[Parameter], normalize: cabc.Callable[[str], str] diff --git a/tests/test_commands.py b/tests/test_commands.py index 2f3a9c87c..7e23bfc70 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -611,6 +611,25 @@ def cli(a, opt, flag, point): assert ctx.args == extra +def test_resilient_parsing_keeps_consumed_args(): + """When a later argument has partial values, the values already assigned to + earlier arguments aren't left over as extra args. + """ + + @click.command() + @click.argument("a", nargs=2) + @click.argument("b", nargs=2) + def cli(a, b): + pass + + with pytest.raises(click.UsageError): + cli.make_context("cli", ["x", "y", "z"]) + + ctx = cli.make_context("cli", ["x", "y", "z"], resilient_parsing=True) + assert ctx.params == {"a": ("x", "y"), "b": None} + assert ctx.args == ["z"] + + @pytest.mark.parametrize("doc", ["CLI HELP", None]) @pytest.mark.parametrize("deprecated", [True, "USE OTHER COMMAND INSTEAD"]) def test_deprecated_in_help_messages(runner, doc, deprecated): From 4e32cda76eaf0026f58cf70d060a255ebd486e0a Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:21:56 -0800 Subject: [PATCH 14/18] Use dataclass for tables. --- src/click/core.py | 67 +++++++++++++++++++++++++++++-------------- tests/test_imports.py | 1 + 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/click/core.py b/src/click/core.py index 59dae4c2d..521d975a6 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -15,6 +15,7 @@ from contextlib import AbstractContextManager from contextlib import contextmanager from contextlib import ExitStack +from dataclasses import dataclass from functools import update_wrapper from gettext import gettext as _ from gettext import ngettext @@ -976,6 +977,30 @@ def get_parameter_source(self, name: str) -> ParameterSource | None: return self._parameter_source.get(name) +@dataclass +class _OptTables: + """A command's parameters arranged for looking up tokens during parsing. + Option names are normalized with the context's ``token_normalize_func``. + """ + + short_opts: dict[str, Option] + """Map each short name, like ``-a``, to its option.""" + + long_opts: dict[str, Option] + """Map each long name, like ``--a`` or ``-ab``, to its option.""" + + secondary_opts: set[str] + """The secondary names of boolean flags, like ``--no-a``.""" + + opt_prefixes: set[str] + """The one and two character prefixes used by options, to check if a token + looks like an option. + """ + + arg_params: list[Argument] + """The positional arguments, in order.""" + + class Command: """Commands are the basic building block of command line interfaces in Click. A basic command handles command line parsing and might dispatch @@ -1393,12 +1418,10 @@ def normalize(name: str) -> str: return f"{prefix}{token_normalize_func(name)}" params = self.get_params(ctx) - short_opts, long_opts, secondary_opts, opt_prefixes, arg_params = ( - self._build_opt_tables(params, normalize) - ) + tables = self._build_opt_tables(params, normalize) def looks_like_opt(token: str) -> bool: - return len(token) > 1 and token[:1] in opt_prefixes + return len(token) > 1 and token[:1] in tables.opt_prefixes def flag_value(opt: Option, name: str) -> t.Any: if opt.count: @@ -1406,7 +1429,7 @@ def flag_value(opt: Option, name: str) -> t.Any: return len(values[opt.name]) + 1 if opt.is_bool_flag and opt.secondary_opts: - return name not in secondary_opts + return name not in tables.secondary_opts return opt.flag_activation_value @@ -1440,9 +1463,9 @@ def flag_value(opt: Option, name: str) -> t.Any: original_name, long_sep, value = token.partition("=") name = normalize(original_name) - if name in long_opts: + if name in tables.long_opts: # any prefix, matching long opt - opt = long_opts[name] + opt = tables.long_opts[name] param_order.append(opt) takes_value = not (opt.is_flag or opt.count) @@ -1472,11 +1495,13 @@ def flag_value(opt: Option, name: str) -> t.Any: looking_for = lf_value_or_opt else: looking_for = lf_value - elif token[:2] in opt_prefixes: + elif token[:2] in tables.opt_prefixes: # long prefix, no matching long opt if not ctx.ignore_unknown_options: raise NoSuchOption( - original_name, possibilities=long_opts, ctx=ctx + original_name, + possibilities=tables.long_opts, + ctx=ctx, ) rest.append(token) @@ -1490,14 +1515,14 @@ def flag_value(opt: Option, name: str) -> t.Any: original_name = f"{prefix}{c}" name = normalize(original_name) - if name not in short_opts: + if name not in tables.short_opts: if not ctx.ignore_unknown_options: raise NoSuchOption(name, ctx=ctx) unmatched.append(c) continue - opt = short_opts[name] + opt = tables.short_opts[name] param_order.append(opt) if opt.is_flag or opt.count: @@ -1600,7 +1625,7 @@ def flag_value(opt: Option, name: str) -> t.Any: ).format(name=looking_opt_name, nargs=looking_opt.nargs) raise BadOptionUsage(looking_opt_name, message, ctx=ctx) - self._assign_args(ctx, arg_params, rest, values, param_order) + self._assign_args(ctx, tables.arg_params, rest, values, param_order) except UsageError: if not ctx.resilient_parsing: raise @@ -1629,7 +1654,7 @@ def flag_value(opt: Option, name: str) -> t.Any: raise BadArgumentUsage(message, ctx=ctx) ctx.args = args - ctx._opt_prefixes.update(opt_prefixes) + ctx._opt_prefixes.update(tables.opt_prefixes) return args @staticmethod @@ -1686,16 +1711,10 @@ def _assign_args( @staticmethod def _build_opt_tables( params: cabc.Sequence[Parameter], normalize: cabc.Callable[[str], str] - ) -> tuple[ - dict[str, Option], dict[str, Option], set[str], set[str], list[Argument] - ]: + ) -> _OptTables: """Map each normalized short and long option name to its option, and collect the positional arguments in order. - Returns the short options, long options, normalized secondary names, option - prefixes, and arguments. The one and two character prefixes used by options - are collected to check if a token looks like an option. - :raise TypeError: Two different option names normalize to the same name. """ opt_prefixes: set[str] = {"-", "--"} @@ -1752,7 +1771,13 @@ def _build_opt_tables( elif isinstance(param, Argument): arg_params.append(param) - return short_opts, long_opts, secondary_opts, opt_prefixes, arg_params + return _OptTables( + short_opts=short_opts, + long_opts=long_opts, + secondary_opts=secondary_opts, + opt_prefixes=opt_prefixes, + arg_params=arg_params, + ) def invoke(self, ctx: Context) -> t.Any: """Given a context, this invokes the attached callback (if it exists) diff --git a/tests/test_imports.py b/tests/test_imports.py index 74b78642b..1fda25cc1 100644 --- a/tests/test_imports.py +++ b/tests/test_imports.py @@ -33,6 +33,7 @@ def tracking_import(module, locals=None, globals=None, fromlist=None, "collections.abc", "configparser", "contextlib", + "dataclasses", "datetime", "enum", "errno", From 0ba0f958969076b1c7bff3dc7a3bbb27007d3762 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:29:00 -0800 Subject: [PATCH 15/18] Factor into _scan_tokens. --- src/click/core.py | 412 ++++++++++++++++++++++++---------------------- 1 file changed, 217 insertions(+), 195 deletions(-) diff --git a/src/click/core.py b/src/click/core.py index 521d975a6..b04eec67b 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -1420,6 +1420,70 @@ def normalize(name: str) -> str: params = self.get_params(ctx) tables = self._build_opt_tables(params, normalize) + # Map parameter names to collected values. + values: defaultdict[str, list[t.Any]] = defaultdict(list) + # Track what order parameters were seen. + param_order: list[Parameter] = [] + # After mapping arguments to values, any extra values will still be here. + rest: list[str] = [] + + try: + self._scan_tokens(ctx, args, tables, normalize, values, param_order, rest) + self._assign_args(ctx, tables.arg_params, rest, values, param_order) + except UsageError: + if not ctx.resilient_parsing: + raise + + args = rest + + for param in iter_params_for_processing(param_order, params): + args = param.handle_parse_result(ctx, values, args)[1] + + # We now have all parameters' values into `ctx.params`, but the data may contain + # the `UNSET` sentinel. + # Convert `UNSET` to `None` to ensure that the user doesn't see `UNSET`. + # + # Waiting until after the initial parse to convert allows us to treat `UNSET` + # more like a missing value when multiple params use the same name. + for name, value in ctx.params.items(): + if value is UNSET: + ctx.params[name] = None + + if args and not ctx.allow_extra_args and not ctx.resilient_parsing: + message = ngettext( + "Got unexpected extra argument ({args})", + "Got unexpected extra arguments ({args})", + len(args), + ).format(args=" ".join(args)) + raise BadArgumentUsage(message, ctx=ctx) + + ctx.args = args + ctx._opt_prefixes.update(tables.opt_prefixes) + return args + + @staticmethod + def _scan_tokens( + ctx: Context, + args: list[str], + tables: _OptTables, + normalize: cabc.Callable[[str], str], + values: defaultdict[str, list[t.Any]], + param_order: list[Parameter], + rest: list[str], + ) -> None: + """Match option tokens to their options and collect their values, leaving + any other tokens in ``rest`` to be assigned to arguments. + + Fills ``values``, ``param_order``, and ``rest`` in place, so that if an + error is raised and ignored for resilient parsing, everything collected so + far is still processed. + + :raise NoSuchOption: An unknown option was given and + ``ignore_unknown_options`` is off. + :raise BadOptionUsage: A flag was given a value, or an option got too few + values. + """ + def looks_like_opt(token: str) -> bool: return len(token) > 1 and token[:1] in tables.opt_prefixes @@ -1433,12 +1497,6 @@ def flag_value(opt: Option, name: str) -> t.Any: return opt.flag_activation_value - # Map parameter names to collected values. - values: defaultdict[str, list[t.Any]] = defaultdict(list) - # Track what order parameters were seen. - param_order: list[Parameter] = [] - # After mapping arguments to values, any extra values will still be here. - rest: list[str] = [] # Track what the parser should do with the current token. lf_any = 0 lf_value_or_opt = 1 @@ -1450,212 +1508,176 @@ def flag_value(opt: Option, name: str) -> t.Any: # Treat tokens as a stack, with the first token at the top. tokens = list(reversed(args)) - try: - while tokens: - token = tokens.pop() + while tokens: + token = tokens.pop() + + if looking_for == lf_any: + if token == "--": + # All tokens after -- are considered arguments. + rest.extend(reversed(tokens)) + tokens.clear() + elif looks_like_opt(token): + original_name, long_sep, value = token.partition("=") + name = normalize(original_name) + + if name in tables.long_opts: + # any prefix, matching long opt + opt = tables.long_opts[name] + param_order.append(opt) + takes_value = not (opt.is_flag or opt.count) + + if long_sep: + # key=value, only valid if the option takes a value + if not takes_value: + message = _( + "Option {name!r} does not take a value." + ).format(name=original_name) + raise BadOptionUsage(original_name, message, ctx=ctx) + + tokens.append(value) + looking_opt = opt + looking_opt_name = original_name + looking_for = lf_value + elif not takes_value: + # no attached value, and no value needed + values[opt.name].append(flag_value(opt, name)) + else: + # no attached value, and a value may be needed + looking_opt = opt + looking_opt_name = original_name - if looking_for == lf_any: - if token == "--": - # All tokens after -- are considered arguments. - rest.extend(reversed(tokens)) - tokens.clear() - elif looks_like_opt(token): - original_name, long_sep, value = token.partition("=") - name = normalize(original_name) + if opt._flag_needs_value: + looking_for = lf_value_or_opt + else: + looking_for = lf_value + elif token[:2] in tables.opt_prefixes: + # long prefix, no matching long opt + if not ctx.ignore_unknown_options: + raise NoSuchOption( + original_name, + possibilities=tables.long_opts, + ctx=ctx, + ) + + rest.append(token) + else: + # short prefix, try short opts + prefix = token[0] + chars = token[1:] + unmatched = [] + + for i, c in enumerate(chars, 1): + original_name = f"{prefix}{c}" + name = normalize(original_name) + + if name not in tables.short_opts: + if not ctx.ignore_unknown_options: + raise NoSuchOption(name, ctx=ctx) + + unmatched.append(c) + continue - if name in tables.long_opts: - # any prefix, matching long opt - opt = tables.long_opts[name] + opt = tables.short_opts[name] param_order.append(opt) - takes_value = not (opt.is_flag or opt.count) - - if long_sep: - # key=value, only valid if the option takes a value - if not takes_value: - message = _( - "Option {name!r} does not take a value." - ).format(name=original_name) - raise BadOptionUsage( - original_name, message, ctx=ctx - ) + if opt.is_flag or opt.count: + # Record the flag, then continue trying short opts. + values[opt.name].append(flag_value(opt, name)) + continue + + # Not a flag, stop trying short options and begin + # looking for values. + looking_opt = opt + looking_opt_name = original_name + value = chars[i:] + + if value: + # Use any remaining chars as a value. tokens.append(value) - looking_opt = opt - looking_opt_name = original_name looking_for = lf_value - elif not takes_value: - # no attached value, and no value needed - values[opt.name].append(flag_value(opt, name)) + elif opt._flag_needs_value: + looking_for = lf_value_or_opt else: - # no attached value, and a value may be needed - looking_opt = opt - looking_opt_name = original_name - - if opt._flag_needs_value: - looking_for = lf_value_or_opt - else: - looking_for = lf_value - elif token[:2] in tables.opt_prefixes: - # long prefix, no matching long opt - if not ctx.ignore_unknown_options: - raise NoSuchOption( - original_name, - possibilities=tables.long_opts, - ctx=ctx, - ) - - rest.append(token) - else: - # short prefix, try short opts - prefix = token[0] - chars = token[1:] - unmatched = [] - - for i, c in enumerate(chars, 1): - original_name = f"{prefix}{c}" - name = normalize(original_name) - - if name not in tables.short_opts: - if not ctx.ignore_unknown_options: - raise NoSuchOption(name, ctx=ctx) - - unmatched.append(c) - continue - - opt = tables.short_opts[name] - param_order.append(opt) - - if opt.is_flag or opt.count: - # Record the flag, then continue trying short opts. - values[opt.name].append(flag_value(opt, name)) - continue - - # Not a flag, stop trying short options and begin - # looking for values. - looking_opt = opt - looking_opt_name = original_name - value = chars[i:] - - if value: - # Use any remaining chars as a value. - tokens.append(value) - looking_for = lf_value - elif opt._flag_needs_value: - looking_for = lf_value_or_opt - else: - looking_for = lf_value - - break - - if unmatched: - # If unknown options are allowed, add any unused chars - # back as a single name with the same prefix. - rest.append(f"{prefix}{''.join(unmatched)}") - else: - # an argument - rest.append(token) + looking_for = lf_value - if not ctx.allow_interspersed_args: - # If interspersed isn't allowed, all remaining - # tokens are considered arguments. - rest.extend(reversed(tokens)) - tokens.clear() - elif looking_for == lf_value_or_opt: - # The current opt optionally takes a value. Look at the - # token then put it back. - assert looking_opt is not None - tokens.append(token) - - if (looking_opt.nargs == 1 and looks_like_opt(token)) or len( - tokens - ) < looking_opt.nargs: - # Next token is an opt, or there aren't enough tokens left. - # Mark the current opt as needing a value, handled during - # processing. - values[looking_opt.name].append(FLAG_NEEDS_VALUE) - looking_opt = looking_opt_name = None - looking_for = lf_any - else: - # Next token will be used as a value. - looking_for = lf_value - elif looking_for == lf_value: - # The current opt requires at least one value. - assert looking_opt is not None and looking_opt_name is not None - - if looking_opt.nargs == 1: - # Exactly one value required - values[looking_opt.name].append(token) - else: - # More than one value required - need_n = looking_opt.nargs - 1 - - if len(tokens) < need_n: - message = ngettext( - "Option {name!r} requires {nargs} values" - " but 1 was given.", - "Option {name!r} requires {nargs} values" - " but {len} were given.", - len(tokens) + 1, - ).format( - name=looking_opt_name, - nargs=looking_opt.nargs, - len=len(tokens) + 1, - ) - raise BadOptionUsage(looking_opt_name, message, ctx=ctx) + break - values[looking_opt.name].append( - (token, *reversed(tokens[-need_n:])) - ) - del tokens[-need_n:] + if unmatched: + # If unknown options are allowed, add any unused chars + # back as a single name with the same prefix. + rest.append(f"{prefix}{''.join(unmatched)}") + else: + # an argument + rest.append(token) + if not ctx.allow_interspersed_args: + # If interspersed isn't allowed, all remaining + # tokens are considered arguments. + rest.extend(reversed(tokens)) + tokens.clear() + elif looking_for == lf_value_or_opt: + # The current opt optionally takes a value. Look at the + # token then put it back. + assert looking_opt is not None + tokens.append(token) + + if (looking_opt.nargs == 1 and looks_like_opt(token)) or len( + tokens + ) < looking_opt.nargs: + # Next token is an opt, or there aren't enough tokens left. + # Mark the current opt as needing a value, handled during + # processing. + values[looking_opt.name].append(FLAG_NEEDS_VALUE) looking_opt = looking_opt_name = None looking_for = lf_any - - if looking_for == lf_value_or_opt: - # No more tokens, mark the current opt to get a value later. - assert looking_opt is not None - values[looking_opt.name].append(FLAG_NEEDS_VALUE) + else: + # Next token will be used as a value. + looking_for = lf_value elif looking_for == lf_value: - # No more tokens, but the current opt still required a value. + # The current opt requires at least one value. assert looking_opt is not None and looking_opt_name is not None - message = ngettext( - "Option {name!r} requires a value.", - "Option {name!r} requires {nargs} values.", - looking_opt.nargs, - ).format(name=looking_opt_name, nargs=looking_opt.nargs) - raise BadOptionUsage(looking_opt_name, message, ctx=ctx) - - self._assign_args(ctx, tables.arg_params, rest, values, param_order) - except UsageError: - if not ctx.resilient_parsing: - raise - - args = rest - - for param in iter_params_for_processing(param_order, params): - args = param.handle_parse_result(ctx, values, args)[1] - # We now have all parameters' values into `ctx.params`, but the data may contain - # the `UNSET` sentinel. - # Convert `UNSET` to `None` to ensure that the user doesn't see `UNSET`. - # - # Waiting until after the initial parse to convert allows us to treat `UNSET` - # more like a missing value when multiple params use the same name. - for name, value in ctx.params.items(): - if value is UNSET: - ctx.params[name] = None + if looking_opt.nargs == 1: + # Exactly one value required + values[looking_opt.name].append(token) + else: + # More than one value required + need_n = looking_opt.nargs - 1 + + if len(tokens) < need_n: + message = ngettext( + "Option {name!r} requires {nargs} values but 1 was given.", + "Option {name!r} requires {nargs} values" + " but {len} were given.", + len(tokens) + 1, + ).format( + name=looking_opt_name, + nargs=looking_opt.nargs, + len=len(tokens) + 1, + ) + raise BadOptionUsage(looking_opt_name, message, ctx=ctx) - if args and not ctx.allow_extra_args and not ctx.resilient_parsing: + values[looking_opt.name].append( + (token, *reversed(tokens[-need_n:])) + ) + del tokens[-need_n:] + + looking_opt = looking_opt_name = None + looking_for = lf_any + + if looking_for == lf_value_or_opt: + # No more tokens, mark the current opt to get a value later. + assert looking_opt is not None + values[looking_opt.name].append(FLAG_NEEDS_VALUE) + elif looking_for == lf_value: + # No more tokens, but the current opt still required a value. + assert looking_opt is not None and looking_opt_name is not None message = ngettext( - "Got unexpected extra argument ({args})", - "Got unexpected extra arguments ({args})", - len(args), - ).format(args=" ".join(args)) - raise BadArgumentUsage(message, ctx=ctx) - - ctx.args = args - ctx._opt_prefixes.update(tables.opt_prefixes) - return args + "Option {name!r} requires a value.", + "Option {name!r} requires {nargs} values.", + looking_opt.nargs, + ).format(name=looking_opt_name, nargs=looking_opt.nargs) + raise BadOptionUsage(looking_opt_name, message, ctx=ctx) @staticmethod def _assign_args( From 1ef22c0d2d94b7d52c0d17a80f09ee2e0a85e8f4 Mon Sep 17 00:00:00 2001 From: Edward Girling <67291205+Rowlando13@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:32:11 -0800 Subject: [PATCH 16/18] Move methods to invocation order. --- src/click/core.py | 142 +++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/src/click/core.py b/src/click/core.py index b04eec67b..bddf0e8da 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -1461,6 +1461,77 @@ def normalize(name: str) -> str: ctx._opt_prefixes.update(tables.opt_prefixes) return args + @staticmethod + def _build_opt_tables( + params: cabc.Sequence[Parameter], normalize: cabc.Callable[[str], str] + ) -> _OptTables: + """Map each normalized short and long option name to its option, and collect + the positional arguments in order. + + :raise TypeError: Two different option names normalize to the same name. + """ + opt_prefixes: set[str] = {"-", "--"} + short_opts: dict[str, Option] = {} + long_opts: dict[str, Option] = {} + # Normalized secondary names, for easier comparison during parsing. + secondary_opts: set[str] = set() + arg_params: list[Argument] = [] + # Normalized name to the option, declared spelling, and whether it's a + # secondary name, to detect spellings that only collide after normalizing. + claimed: dict[str, tuple[Option, str, bool]] = {} + + for param in params: + if isinstance(param, Option): + names = [(n, False) for n in param.opts] + + if param.is_bool_flag and param.secondary_opts: + names.extend((n, True) for n in param.secondary_opts) + secondary_opts.update(normalize(n) for n in param.secondary_opts) + + for original, is_secondary in names: + name = normalize(original) + + if name in claimed: + other, other_original, other_is_secondary = claimed[name] + + # An identical spelling is a duplicate declaration, which + # get_params warns about, and the last one keeps winning. + if original != other_original and ( + other is not param or other_is_secondary != is_secondary + ): + raise TypeError( + _( + "The option names {first!r} and {second!r} both" + " normalize to {name!r}. Give them names that" + " stay distinct after 'token_normalize_func'." + ).format( + first=other_original, second=original, name=name + ) + ) + + claimed[name] = (param, original, is_secondary) + prefix, value = _split_opt(name) + opt_prefixes.add(prefix[0]) + + if len(prefix) == 1 and len(value) == 1: + # -a is a short opt + short_opts[name] = param + else: + # --a is a long opt, -ab is a long opt with a short prefix + opt_prefixes.add(prefix) + long_opts[name] = param + + elif isinstance(param, Argument): + arg_params.append(param) + + return _OptTables( + short_opts=short_opts, + long_opts=long_opts, + secondary_opts=secondary_opts, + opt_prefixes=opt_prefixes, + arg_params=arg_params, + ) + @staticmethod def _scan_tokens( ctx: Context, @@ -1730,77 +1801,6 @@ def _assign_args( ).format(name=arg.make_metavar(ctx), nargs=arg.nargs, len=len(rest)) raise BadArgumentUsage(message, ctx=ctx) - @staticmethod - def _build_opt_tables( - params: cabc.Sequence[Parameter], normalize: cabc.Callable[[str], str] - ) -> _OptTables: - """Map each normalized short and long option name to its option, and collect - the positional arguments in order. - - :raise TypeError: Two different option names normalize to the same name. - """ - opt_prefixes: set[str] = {"-", "--"} - short_opts: dict[str, Option] = {} - long_opts: dict[str, Option] = {} - # Normalized secondary names, for easier comparison during parsing. - secondary_opts: set[str] = set() - arg_params: list[Argument] = [] - # Normalized name to the option, declared spelling, and whether it's a - # secondary name, to detect spellings that only collide after normalizing. - claimed: dict[str, tuple[Option, str, bool]] = {} - - for param in params: - if isinstance(param, Option): - names = [(n, False) for n in param.opts] - - if param.is_bool_flag and param.secondary_opts: - names.extend((n, True) for n in param.secondary_opts) - secondary_opts.update(normalize(n) for n in param.secondary_opts) - - for original, is_secondary in names: - name = normalize(original) - - if name in claimed: - other, other_original, other_is_secondary = claimed[name] - - # An identical spelling is a duplicate declaration, which - # get_params warns about, and the last one keeps winning. - if original != other_original and ( - other is not param or other_is_secondary != is_secondary - ): - raise TypeError( - _( - "The option names {first!r} and {second!r} both" - " normalize to {name!r}. Give them names that" - " stay distinct after 'token_normalize_func'." - ).format( - first=other_original, second=original, name=name - ) - ) - - claimed[name] = (param, original, is_secondary) - prefix, value = _split_opt(name) - opt_prefixes.add(prefix[0]) - - if len(prefix) == 1 and len(value) == 1: - # -a is a short opt - short_opts[name] = param - else: - # --a is a long opt, -ab is a long opt with a short prefix - opt_prefixes.add(prefix) - long_opts[name] = param - - elif isinstance(param, Argument): - arg_params.append(param) - - return _OptTables( - short_opts=short_opts, - long_opts=long_opts, - secondary_opts=secondary_opts, - opt_prefixes=opt_prefixes, - arg_params=arg_params, - ) - def invoke(self, ctx: Context) -> t.Any: """Given a context, this invokes the attached callback (if it exists) in the right way. From 73a6ad0c6daf8cacf911e3c0819f7a7a000f9d86 Mon Sep 17 00:00:00 2001 From: "edward.g2013" Date: Tue, 1 Dec 2026 21:31:38 +0000 Subject: [PATCH 17/18] Note _base_utils use for unwinding core.py circular imports. --- src/click/_base_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/click/_base_utils.py b/src/click/_base_utils.py index e2d42f7ab..39d4b3ddd 100644 --- a/src/click/_base_utils.py +++ b/src/click/_base_utils.py @@ -1,5 +1,6 @@ # Private utilities that must not import anything else from the package. Keeping # them dependency-free lets any module use them without creating circular imports. +# This module will also be used to help unwind circular imports in core.py. from __future__ import annotations From 9fc187deea7c59c3452846040b4ca1d57acbc427 Mon Sep 17 00:00:00 2001 From: "edward.g2013" Date: Tue, 1 Dec 2026 21:38:43 +0000 Subject: [PATCH 18/18] Remove empty _parser.py and note better parse error messages. --- CHANGES.md | 1 + src/click/_parser.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 src/click/_parser.py diff --git a/CHANGES.md b/CHANGES.md index 9f6261474..0e9a0ad6a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ Unreleased - `Command.make_parser` and `Parameter.add_to_parser` are removed. - `Context.protected_args` always returns an empty list. The subcommand name and its arguments are in `Context.args`. + - Better error messages when parsing fails. - Option names that only become equal after `token_normalize_func`, such as `-v` and `-V` with a lower-casing function, raise a `TypeError` when parsing diff --git a/src/click/_parser.py b/src/click/_parser.py deleted file mode 100644 index 9d48db4f9..000000000 --- a/src/click/_parser.py +++ /dev/null @@ -1 +0,0 @@ -from __future__ import annotations