Skip to content
Myr

use positional-only arg instead of `__self` (#2660)

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

authored by David Lord · committed by GitHub · parents c364303, 5e08ef1 · Browse files · 1 file+17 added−17 removed
This commit

State

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

Diff stats

1 file+17 added−17 removed

  • other:+17 added−17 removed

1 file+17 added−17 removed

modified:src/click/core.py+17 added-17 removed
722 unmodified lines
723 return type(self)(command, info_name=command.name, parent=self)724725 @t.overload726 def invoke(727 __self, __callback: t.Callable[..., V], *args: t.Any, **kwargs: t.Any727 self, callback: t.Callable[..., V], /, *args: t.Any, **kwargs: t.Any728 ) -> V:729 ...730731 @t.overload732 def invoke(__self, __callback: Command, *args: t.Any, **kwargs: t.Any) -> t.Any:732 def invoke(self, callback: Command, /, *args: t.Any, **kwargs: t.Any) -> t.Any:733 ...734735 def invoke(736 __self, __callback: Command | t.Callable[..., V], *args: t.Any, **kwargs: t.Any736 self, callback: Command | t.Callable[..., V], /, *args: t.Any, **kwargs: t.Any737 ) -> t.Any | V:738 """Invokes a command callback in exactly the way it expects. There739 are two ways to invoke this method:740
10 unmodified lines
751752 .. versionchanged:: 3.2753 A new context is created, and missing arguments use default values.754 """755 if isinstance(__callback, Command):756 other_cmd = __callback755 if isinstance(callback, Command):756 other_cmd = callback757758 if other_cmd.callback is None:759 raise TypeError(760 "The given command does not have a callback that can be invoked."761 )762 else:763 __callback = t.cast("t.Callable[..., V]", other_cmd.callback)763 callback = t.cast("t.Callable[..., V]", other_cmd.callback)764765 ctx = __self._make_sub_context(other_cmd)765 ctx = self._make_sub_context(other_cmd)766767 for param in other_cmd.params:768 if param.name not in kwargs and param.expose_value:769 kwargs[param.name] = param.type_cast_value( # type: ignore
3 unmodified lines
773 # Track all kwargs as params, so that forward() will pass774 # them on in subsequent calls.775 ctx.params.update(kwargs)776 else:777 ctx = __self777 ctx = self778779 with augment_usage_errors(__self):779 with augment_usage_errors(self):780 with ctx:781 return __callback(*args, **kwargs)781 return callback(*args, **kwargs)782783 def forward(__self, __cmd: Command, *args: t.Any, **kwargs: t.Any) -> t.Any:783 def forward(self, cmd: Command, /, *args: t.Any, **kwargs: t.Any) -> t.Any:784 """Similar to :meth:`invoke` but fills in default keyword785 arguments from the current context if the other command expects786 it. This cannot invoke callbacks directly, only other commands.787
1 unmodified line
789 All ``kwargs`` are tracked in :attr:`params` so they will be790 passed if ``forward`` is called at multiple levels.791 """792 # Can only forward to other commands, not direct callbacks.793 if not isinstance(__cmd, Command):793 if not isinstance(cmd, Command):794 raise TypeError("Callback is not a command.")795796 for param in __self.params:796 for param in self.params:797 if param not in kwargs:798 kwargs[param] = __self.params[param]798 kwargs[param] = self.params[param]799800 return __self.invoke(__cmd, *args, **kwargs)800 return self.invoke(cmd, *args, **kwargs)801802 def set_parameter_source(self, name: str, source: ParameterSource) -> None:803 """Set the source of a parameter. This indicates the location804 from which the value of the parameter was obtained.
868 unmodified lines
1673 if old_callback is None or replace:1674 self._result_callback = f1675 return f16761677 def function(__value, *args, **kwargs): # type: ignore1678 inner = old_callback(__value, *args, **kwargs)1677 def function(value: t.Any, /, *args: t.Any, **kwargs: t.Any) -> t.Any:1678 inner = old_callback(value, *args, **kwargs)1679 return f(inner, *args, **kwargs)16801681 self._result_callback = rv = update_wrapper(t.cast(F, function), f)1682 return rv
1302 unmodified lines