Skip to content

Commit cab9483

Browse files
authored
use positional-only arg instead of __self (pallets#2660)
2 parents c364303 + 5e08ef1 commit cab9483

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/click/core.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -724,16 +724,16 @@ def _make_sub_context(self, command: Command) -> Context:
724724

725725
@t.overload
726726
def invoke(
727-
__self, __callback: t.Callable[..., V], *args: t.Any, **kwargs: t.Any
727+
self, callback: t.Callable[..., V], /, *args: t.Any, **kwargs: t.Any
728728
) -> V:
729729
...
730730

731731
@t.overload
732-
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:
733733
...
734734

735735
def invoke(
736-
__self, __callback: Command | t.Callable[..., V], *args: t.Any, **kwargs: t.Any
736+
self, callback: Command | t.Callable[..., V], /, *args: t.Any, **kwargs: t.Any
737737
) -> t.Any | V:
738738
"""Invokes a command callback in exactly the way it expects. There
739739
are two ways to invoke this method:
@@ -752,17 +752,17 @@ def invoke(
752752
.. versionchanged:: 3.2
753753
A new context is created, and missing arguments use default values.
754754
"""
755-
if isinstance(__callback, Command):
756-
other_cmd = __callback
755+
if isinstance(callback, Command):
756+
other_cmd = callback
757757

758758
if other_cmd.callback is None:
759759
raise TypeError(
760760
"The given command does not have a callback that can be invoked."
761761
)
762762
else:
763-
__callback = t.cast("t.Callable[..., V]", other_cmd.callback)
763+
callback = t.cast("t.Callable[..., V]", other_cmd.callback)
764764

765-
ctx = __self._make_sub_context(other_cmd)
765+
ctx = self._make_sub_context(other_cmd)
766766

767767
for param in other_cmd.params:
768768
if param.name not in kwargs and param.expose_value:
@@ -774,13 +774,13 @@ def invoke(
774774
# them on in subsequent calls.
775775
ctx.params.update(kwargs)
776776
else:
777-
ctx = __self
777+
ctx = self
778778

779-
with augment_usage_errors(__self):
779+
with augment_usage_errors(self):
780780
with ctx:
781-
return __callback(*args, **kwargs)
781+
return callback(*args, **kwargs)
782782

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:
784784
"""Similar to :meth:`invoke` but fills in default keyword
785785
arguments from the current context if the other command expects
786786
it. This cannot invoke callbacks directly, only other commands.
@@ -790,14 +790,14 @@ def forward(__self, __cmd: Command, *args: t.Any, **kwargs: t.Any) -> t.Any:
790790
passed if ``forward`` is called at multiple levels.
791791
"""
792792
# Can only forward to other commands, not direct callbacks.
793-
if not isinstance(__cmd, Command):
793+
if not isinstance(cmd, Command):
794794
raise TypeError("Callback is not a command.")
795795

796-
for param in __self.params:
796+
for param in self.params:
797797
if param not in kwargs:
798-
kwargs[param] = __self.params[param]
798+
kwargs[param] = self.params[param]
799799

800-
return __self.invoke(__cmd, *args, **kwargs)
800+
return self.invoke(cmd, *args, **kwargs)
801801

802802
def set_parameter_source(self, name: str, source: ParameterSource) -> None:
803803
"""Set the source of a parameter. This indicates the location
@@ -1674,8 +1674,8 @@ def decorator(f: F) -> F:
16741674
self._result_callback = f
16751675
return f
16761676

1677-
def function(__value, *args, **kwargs): # type: ignore
1678-
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)
16791679
return f(inner, *args, **kwargs)
16801680

16811681
self._result_callback = rv = update_wrapper(t.cast(F, function), f)

0 commit comments

Comments
 (0)