Skip to content
Myr

Do not simple-tick Python literal values

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kevin Deldycke · committed by Kevin Deldycke · parent b64ea07 · Browse files · 1 file+33 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Refs: https://github.com/pallets/click/pull/3030#discussion_r2288948990

Diff stats

1 file+33 added−33 removed

  • other:+33 added−33 removed

1 file+33 added−33 removed

modified:src/click/core.py+33 added-33 removed
185 unmodified lines
186 the name of the script, for commands below it it's187 the name of the script.188 :param obj: an arbitrary object of user data.189 :param auto_envvar_prefix: the prefix to use for automatic environment190 variables. If this is `None` then reading190 variables. If this is ``None`` then reading191 from environment variables is disabled. This192 does not affect manually set environment193 variables which are always read.194 :param default_map: a dictionary (like object) with default values
14 unmodified lines
209 parse without any interactivity or callback210 invocation. Default values will also be211 ignored. This is useful for implementing212 things such as completion support.213 :param allow_extra_args: if this is set to `True` then extra arguments213 :param allow_extra_args: if this is set to ``True`` then extra arguments214 at the end will not raise an error and will be215 kept on the context. The default is to inherit216 from the command.217 :param allow_interspersed_args: if this is set to `False` then options217 :param allow_interspersed_args: if this is set to ``False`` then options218 and arguments cannot be mixed. The219 default is to inherit from the command.220 :param ignore_unknown_options: instructs click to ignore options it does221 not know and keeps them for later
66 unmodified lines
288 token_normalize_func: t.Callable[[str], str] | None = None,289 color: bool | None = None,290 show_default: bool | None = None,291 ) -> None:292 #: the parent context or `None` if none exists.292 #: the parent context or ``None`` if none exists.293 self.parent = parent294 #: the :class:`Command` for this context.295 self.command = command296 #: the descriptive information name
196 unmodified lines
493 def scope(self, cleanup: bool = True) -> cabc.Iterator[Context]:494 """This helper method can be used with the context object to promote495 it to the current thread local (see :func:`get_current_context`).496 The default behavior of this is to invoke the cleanup functions which497 can be disabled by setting `cleanup` to `False`. The cleanup497 can be disabled by setting `cleanup` to ``False``. The cleanup498 functions are typically used for things such as closing file handles.499500 If the cleanup is intended the context object can also be directly501 used as a context manager.
332 unmodified lines
834 :param name: The name of the parameter.835 :rtype: ParameterSource836837 .. versionchanged:: 8.0838 Returns `None` if the parameter was not provided from any838 Returns ``None`` if the parameter was not provided from any839 source.840 """841 return self._parameter_source.get(name)842
20 unmodified lines
863 provided. This option is disabled by default.864 If enabled this will add ``--help`` as argument865 if no arguments are passed866 :param hidden: hide this command from help outputs.867 :param deprecated: If `True` or non-empty string, issues a message867 :param deprecated: If ``True`` or non-empty string, issues a message868 indicating that the command is deprecated and highlights869 its deprecation in --help. The message can be customized870 by using a string as the value.871
58 unmodified lines
930 #: an optional dictionary with defaults passed to the context.931 self.context_settings: cabc.MutableMapping[str, t.Any] = context_settings932933 #: the callback to execute when the command fires. This might be934 #: `None` in which case nothing happens.934 #: ``None`` in which case nothing happens.935 self.callback = callback936 #: the list of parameters for this command in the order they937 #: should show up in the help page and execute. Eager parameters938 #: will automatically be handled before non eager ones.
85 unmodified lines
10241025 def get_help_option(self, ctx: Context) -> Option | None:1026 """Returns the help option object.10271028 Skipped if :attr:`add_help_option` is `False`.1028 Skipped if :attr:`add_help_option` is ``False``.10291030 .. versionchanged:: 8.1.81031 The help option is now cached to avoid creating it multiple times.1032 """
290 unmodified lines
1323 in standalone mode. Click will then1324 handle exceptions and convert them into1325 error messages and the function will never1326 return but shut down the interpreter. If1327 this is set to `False` they will be1327 this is set to ``False`` they will be1328 propagated to the caller and the return1329 value of this function is the return value1330 of :meth:`invoke`.1331 :param windows_expand_args: Expand glob patterns, user dir, and
35 unmodified lines
1367 # it's not safe to `ctx.exit(rv)` here!1368 # note that `rv` may actually contain data like "1" which1369 # has obvious effects1370 # more subtle case: `rv=[None, None]` can come out of1371 # chained commands which all returned `None` -- so it's not1371 # chained commands which all returned ``None`` -- so it's not1372 # even always obvious that `rv` indicates success/failure1373 # by its truthiness/falsiness1374 ctx.exit()1375 except (EOFError, KeyboardInterrupt) as e:
331 unmodified lines
1707 @cli.result_callback()1708 def process_result(result, input):1709 return result + input17101711 :param replace: if set to `True` an already existing result1711 :param replace: if set to ``True`` an already existing result1712 callback will be removed.17131714 .. versionchanged:: 8.01715 Renamed from ``resultcallback``.
18 unmodified lines
1734 return decorator17351736 def get_command(self, ctx: Context, cmd_name: str) -> Command | None:1737 """Given a context and a command name, this returns a :class:`Command`1738 object if it exists or returns `None`.1738 object if it exists or returns ``None``.1739 """1740 return self.commands.get(cmd_name)17411742 def list_commands(self, ctx: Context) -> list[str]:
266 unmodified lines
2009 nargs is ``1`` (except if the type is a tuple, then it's2010 the arity of the tuple). If ``nargs=-1``, all remaining2011 parameters are collected.2012 :param metavar: how the value is represented in the help page.2013 :param expose_value: if this is `True` then the value is passed onwards2013 :param expose_value: if this is ``True`` then the value is passed onwards2014 to the command callback and stored on the context,2015 otherwise it's skipped.2016 :param is_eager: eager values are processed before non eager ones. This2017 should not be set for arguments or it will inverse the
6 unmodified lines
2024 completions. Used instead of the param's type completion if2025 given. Takes ``ctx, param, incomplete`` and must return a list2026 of :class:`~click.shell_completion.CompletionItem` or a list of2027 strings.2028 :param deprecated: If `True` or non-empty string, issues a message2028 :param deprecated: If ``True`` or non-empty string, issues a message2029 indicating that the argument is deprecated and highlights2030 its deprecation in --help. The message can be customized2031 by using a string as the value. A deprecated parameter2032 cannot be required, a ValueError will be raised otherwise.
26 unmodified lines
2059 tuples.20602061 .. versionchanged:: 8.02062 Setting a default is no longer required for ``nargs>1``, it will2063 default to `None`. ``multiple=True`` or ``nargs=-1`` will2063 default to ``None``. ``multiple=True`` or ``nargs=-1`` will2064 default to ``()``.20652066 .. versionchanged:: 7.12067 Empty environment variables are ignored rather than taking the
76 unmodified lines
2144 Use :meth:`click.Context.to_info_dict` to traverse the entire2145 CLI structure.21462147 .. versionchanged:: 8.3.02148 Returns `None` for the :attr:`default` if it is :attr:`UNSET`.2148 Returns ``None`` for the :attr:`default` if it is :attr:`UNSET`.21492150 We explicitly hide the :attr:`UNSET` value to the user, as we choose to2151 make it an implementation detail. And because ``to_info_dict`` has been2152 designed for documentation purposes, we return `None` instead.2152 designed for documentation purposes, we return ``None`` instead.21532154 .. versionadded:: 8.02155 """2156 return {
210 unmodified lines
2367 The :attr:`callback` is now receiving the :attr:`UNSET` sentinel if the2368 parameter is not given by the CLI user.23692370 The callback is receiving the value as-is, which let the developer decide2371 how to handle the different cases of `None`, ``UNSET``, or any other value.2371 how to handle the different cases of ``None``, ``UNSET``, or any other value.2372 """2373 value = self.type_cast_value(ctx, value)23742375 if self.required and self.value_is_missing(value):
10 unmodified lines
23862387 Environment variables values are `always returned as strings2388 <https://docs.python.org/3/library/os.html#os.environ>`_.23892390 This method returns `None` if:2390 This method returns ``None`` if:23912392 - the :attr:`envvar` property is not set on the :class:`Parameter`,2393 - the environment variable is not found in the environment,2394 - the variable is found in the environment but its value is empty (i.e. the
135 unmodified lines
2530 All other parameters are passed onwards to the parameter constructor.25312532 :param show_default: Show the default value for this option in its2533 help text. Values are not shown by default, unless2534 :attr:`Context.show_default` is `True`. If this value is a2534 :attr:`Context.show_default` is ``True``. If this value is a2535 string, it shows that string in parentheses instead of the2536 actual value. This is particularly useful for dynamic options.2537 For single option boolean flags, the default remains hidden if2538 its value is `False`.2538 its value is ``False``.2539 :param show_envvar: Controls if an environment variable should be2540 shown on the help page and error messages.2541 Normally, environment variables are not shown.2542 :param prompt: If set to `True` or a non empty string then the2543 user will be prompted for input. If set to `True` the prompt2542 :param prompt: If set to ``True`` or a non empty string then the2543 user will be prompted for input. If set to ``True`` the prompt2544 will be the option name capitalized. A deprecated option cannot be2545 prompted.2546 :param confirmation_prompt: Prompt a second time to confirm the2547 value if it was prompted for. Can be set to a string instead of2548 `True` to customize the message.2549 :param prompt_required: If set to `False`, the user will be2548 ``True`` to customize the message.2549 :param prompt_required: If set to ``False``, the user will be2550 prompted for input only when the option was specified as a flag2551 without a value.2552 :param hide_input: If this is `True` then the input on the prompt2552 :param hide_input: If this is ``True`` then the input on the prompt2553 will be hidden from the user. This is useful for password input.2554 :param is_flag: forces this option to act as a flag. The default is2555 auto detection.2556 :param flag_value: which value should be used for this flag if it's2557 enabled. This is set to a boolean automatically if2558 the option string contains a slash to mark two options.2559 :param multiple: if this is set to `True` then the argument is accepted2559 :param multiple: if this is set to ``True`` then the argument is accepted2560 multiple times and recorded. This is similar to ``nargs``2561 in how it works but supports arbitrary number of2562 arguments.2563 :param count: this flag makes an option increment an integer.
18 unmodified lines
2582 ``Context.show_default``.25832584 .. versionchanged:: 8.12585 The default of a single option boolean flag is not shown if the2586 default value is `False`.2586 default value is ``False``.25872588 .. versionchanged:: 8.0.12589 ``type`` is detected from ``flag_value`` if given.2590 """
150 unmodified lines
27412742 def to_info_dict(self) -> dict[str, t.Any]:2743 """2744 .. versionchanged:: 8.3.02745 Returns `None` for the :attr:`flag_value` if it is :attr:`UNSET`.2745 Returns ``None`` for the :attr:`flag_value` if it is :attr:`UNSET`.27462747 We explicitly hide the :attr:`UNSET` value to the user, as we choose to2748 make it an implementation detail. And because ``to_info_dict`` has been2749 designed for documentation purposes, we return `None` instead.2749 designed for documentation purposes, we return ``None`` instead.2750 """2751 info_dict = super().to_info_dict()2752 info_dict.update(2753 help=self.help,
263 unmodified lines
3017 prompt_kwargs["show_default"] = self.show_default30183019 return prompt(3020 self.prompt,3021 # Use `None` to inform the prompt() function to reiterate until a valid3021 # Use ``None`` to inform the prompt() function to reiterate until a valid3022 # value is provided by the user if we have no default.3023 default=None if default is UNSET else default,3024 type=self.type,3025 hide_input=self.hide_input,
41 unmodified lines
3067 flag is activated or not, and returns a boolean of its activation, or the3068 :attr:`flag_value` if the latter is set.30693070 This method also takes care of repeated options (i.e. options with3071 :attr:`multiple` set to `True`).3071 :attr:`multiple` set to ``True``).3072 """3073 raw_value = self.resolve_envvar_value(ctx)30743075 # Absent environment variable or an empty string is interpreted as unset.
198 unmodified lines