diff options
| author | Myst(MysterialPy) <[email protected]> | 2019-03-01 11:51:36 +1000 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-03-02 06:16:50 -0500 |
| commit | 63c5892b43a1c6f121f9c9c1ccfe6873f10a30e1 (patch) | |
| tree | fd2dbc91a157a40381dcabae357584ca56a8becf | |
| parent | Mock a ConnectionState object to fix wait=True errors in webhooks. (diff) | |
| download | discord.py-63c5892b43a1c6f121f9c9c1ccfe6873f10a30e1.tar.xz discord.py-63c5892b43a1c6f121f9c9c1ccfe6873f10a30e1.zip | |
Fix Signature for Greedy/Optional converters
Change Greedy to `[a]...` | `[a=1]...`
| -rw-r--r-- | discord/ext/commands/core.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 45c3eb80..5c9da1a2 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -795,11 +795,23 @@ class Command(_BaseCommand): return self.help.split('\n', 1)[0] return '' + def _is_typing_optional(self, annotation): + try: + origin = annotation.__origin__ + except AttributeError: + return False + + if origin is not typing.Union: + return False + + return annotation.__args__[-1] is type(None) + @property def signature(self): """Returns a POSIX-like signature useful for help command output.""" result = [] parent = self.full_parent_name + if len(self.aliases) > 0: aliases = '|'.join(self.aliases) fmt = '[%s|%s]' % (self.name, aliases) @@ -819,16 +831,25 @@ class Command(_BaseCommand): return ' '.join(result) for name, param in params.items(): + greedy = isinstance(param.annotation, converters._Greedy) + if param.default is not param.empty: # We don't want None or '' to trigger the [name=value] case and instead it should # do [name] since [name=None] or [name=] are not exactly useful for the user. should_print = param.default if isinstance(param.default, str) else param.default is not None if should_print: - result.append('[%s=%s]' % (name, param.default)) + result.append('[%s=%s]' % (name, param.default) if not greedy else + '[%s=%s]...' % (name, param.default)) + continue else: result.append('[%s]' % name) + elif param.kind == param.VAR_POSITIONAL: result.append('[%s...]' % name) + elif greedy: + result.append('[%s]...' % name) + elif self._is_typing_optional(param.annotation): + result.append('[%s]' % name) else: result.append('<%s>' % name) |