Add the ability to set the option name with commands.Option #102

Merged
StockerMC merged 5 commits from patch-1 into 2.0 2021-10-16 14:00:57 +00:00
2 changed files with 9 additions and 3 deletions
Showing only changes of commit 8f846ba2f5 - Show all commits

View File

@@ -1039,16 +1039,18 @@ class Option(Generic[T, DT]): # type: ignore
__slots__ = (
"default",
"description",
"name",
)
def __init__(self, default: T = inspect.Parameter.empty, *, description: DT) -> None:
def __init__(self, default: T = inspect.Parameter.empty, *, description: DT, name: str = discord.utils.MISSING) -> None:
self.description = description
self.default = default
self.name: str = name
if TYPE_CHECKING:
# Terrible workaround for type checking reasons
def Option(default: T = inspect.Parameter.empty, *, description: str) -> T:
def Option(default: T = inspect.Parameter.empty, *, description: str, name: str = discord.utils.MISSING) -> T:
...

View File

@@ -174,8 +174,12 @@ def get_signature_parameters(
annotation = parameter.annotation
if isinstance(parameter.default, Option): # type: ignore
option = parameter.default
descriptions[name] = option.description
parameter = parameter.replace(default=option.default)
if option.name is not MISSING:
name = option.name
parameter.replace(name=name)
descriptions[name] = option.description
if annotation is parameter.empty:
params[name] = parameter