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
Provenance
- Commit
cab9483- Tree
24ced7d- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
c364303- Parent 2
5e08ef1
1 file changed+17 added−17 removed
modified:src/click/core.py+17 added-17 removed
722 unmodified lines723 return type(self)(command, info_name=command.name, parent=self)724 725 @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 ...730 731 @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 ...734 735 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 lines751 752 .. 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 = callback757 758 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)764 765- ctx = __self._make_sub_context(other_cmd)765+ ctx = self._make_sub_context(other_cmd)766 767 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: ignore3 unmodified lines773 # 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 = self778 779- with augment_usage_errors(__self):779+ with augment_usage_errors(self):780 with ctx:781- return __callback(*args, **kwargs)781+ return callback(*args, **kwargs)782 783- 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 line789 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.")795 796- 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]799 800- return __self.invoke(__cmd, *args, **kwargs)800+ return self.invoke(cmd, *args, **kwargs)801 802 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 lines1673 if old_callback is None or replace:1674 self._result_callback = f1675 return f1676 1677- 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)1680 1681 self._result_callback = rv = update_wrapper(t.cast(F, function), f)1682 return rv1302 unmodified lines