Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ Speed up method Command.invoke by 6% #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,20 +1196,14 @@ def parse_args(self, ctx: Context, args: list[str]) -> list[str]:
return args

def invoke(self, ctx: Context) -> t.Any:
"""Given a context, this invokes the attached callback (if it exists)
in the right way.
"""
"""Given a context, this invokes the attached callback (if it exists) in the right way."""
if self.deprecated:
extra_message = (
f" {self.deprecated}" if isinstance(self.deprecated, str) else ""
)
message = _(
"DeprecationWarning: The command {name!r} is deprecated."
"{extra_message}"
).format(name=self.name, extra_message=extra_message)
# Create the message efficiently in one step
extra_message = f" {self.deprecated}" if isinstance(self.deprecated, str) else ""
message = _("DeprecationWarning: The command {name!r} is deprecated.{extra_message}").format(name=self.name, extra_message=extra_message)
echo(style(message, fg="red"), err=True)

if self.callback is not None:
if self.callback:
return ctx.invoke(self.callback, **ctx.params)

def shell_complete(self, ctx: Context, incomplete: str) -> list[CompletionItem]:
Expand Down