[commands] Raise TypeError when Optional is used with Greedy converter
This commit is contained in:
parent
6b5be39cd2
commit
7a07644de3
@ -26,6 +26,7 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import inspect
|
import inspect
|
||||||
|
import typing
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
@ -555,6 +556,9 @@ class _Greedy:
|
|||||||
if converter is str or converter is type(None) or converter is _Greedy:
|
if converter is str or converter is type(None) or converter is _Greedy:
|
||||||
raise TypeError('Greedy[%s] is invalid.' % converter.__name__)
|
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)
|
return self.__class__(converter=converter)
|
||||||
|
|
||||||
Greedy = _Greedy()
|
Greedy = _Greedy()
|
||||||
|
@ -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
|
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.
|
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
|
To help aid with some parsing ambiguities, :class:`str`, ``None``, :data:`typing.Optional` and
|
||||||
forbidden as parameters for the :data:`~ext.commands.Greedy` converter.
|
:data:`~ext.commands.Greedy` are forbidden as parameters for the :data:`~ext.commands.Greedy` converter.
|
||||||
|
|
||||||
.. _ext_commands_error_handler:
|
.. _ext_commands_error_handler:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user