aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Law <[email protected]>2020-06-28 00:54:34 -0700
committerGitHub <[email protected]>2020-06-28 03:54:34 -0400
commit7a07644de3dad9defe60d44cca7211b7b7f84134 (patch)
tree63f57954064dbc3ee4ec5ead1f0f83ad5f93af61
parent[tasks] Fix issue with default error handler in class context (diff)
downloaddiscord.py-7a07644de3dad9defe60d44cca7211b7b7f84134.tar.xz
discord.py-7a07644de3dad9defe60d44cca7211b7b7f84134.zip
[commands] Raise TypeError when Optional is used with Greedy converter
-rw-r--r--discord/ext/commands/converter.py4
-rw-r--r--docs/ext/commands/commands.rst4
2 files changed, 6 insertions, 2 deletions
diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py
index 3d706bf8..123b6699 100644
--- a/discord/ext/commands/converter.py
+++ b/discord/ext/commands/converter.py
@@ -26,6 +26,7 @@ DEALINGS IN THE SOFTWARE.
import re
import inspect
+import typing
import discord
@@ -555,6 +556,9 @@ class _Greedy:
if converter is str or converter is type(None) or converter is _Greedy:
raise TypeError('Greedy[%s] is invalid.' % converter.__name__)
+ if getattr(converter, '__origin__', None) is typing.Union and type(None) in converter.__args__:
+ raise TypeError('Greedy[%r] is invalid.' % converter)
+
return self.__class__(converter=converter)
Greedy = _Greedy()
diff --git a/docs/ext/commands/commands.rst b/docs/ext/commands/commands.rst
index fbf87fc2..523de3e3 100644
--- a/docs/ext/commands/commands.rst
+++ b/docs/ext/commands/commands.rst
@@ -552,8 +552,8 @@ This command can be invoked any of the following ways:
unintended parsing ambiguities in your code. One technique would be to clamp down the expected syntaxes
allowed through custom converters or reordering the parameters to minimise clashes.
- To help aid with some parsing ambiguities, :class:`str`, ``None`` and :data:`~ext.commands.Greedy` are
- forbidden as parameters for the :data:`~ext.commands.Greedy` converter.
+ To help aid with some parsing ambiguities, :class:`str`, ``None``, :data:`typing.Optional` and
+ :data:`~ext.commands.Greedy` are forbidden as parameters for the :data:`~ext.commands.Greedy` converter.
.. _ext_commands_error_handler: