aboutsummaryrefslogtreecommitdiff
path: root/discord/ext/commands
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-04-24 09:33:35 -0400
committerRapptz <[email protected]>2021-04-24 09:33:35 -0400
commitc250b9fc0200920ac3ff129f26de0bf18058303a (patch)
tree252d6037230a355a3faf4df809497a5f8a9294ef /discord/ext/commands
parent[commands] Disallow complicated Literal types (diff)
downloaddiscord.py-c250b9fc0200920ac3ff129f26de0bf18058303a.tar.xz
discord.py-c250b9fc0200920ac3ff129f26de0bf18058303a.zip
[commands] Fix regression with Union converters not working
This was due to the Literal restriction from earlier.
Diffstat (limited to 'discord/ext/commands')
-rw-r--r--discord/ext/commands/core.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py
index 7c802873..3c46c1b0 100644
--- a/discord/ext/commands/core.py
+++ b/discord/ext/commands/core.py
@@ -112,6 +112,7 @@ def _evaluate_annotation(
if hasattr(tp, '__args__'):
implicit_str = True
+ is_literal = False
args = tp.__args__
if not hasattr(tp, '__origin__'):
if PY_310 and tp.__class__ is types.Union:
@@ -129,12 +130,13 @@ def _evaluate_annotation(
if not PY_310:
args = flatten_literal_params(tp.__args__)
implicit_str = False
+ is_literal = True
evaluated_args = tuple(
_evaluate_annotation(arg, globals, locals, cache, implicit_str=implicit_str) for arg in args
)
- if not all(isinstance(x, (str, int, bool, float, complex)) for x in evaluated_args):
+ if is_literal and not all(isinstance(x, (str, int, bool, float, complex)) for x in evaluated_args):
raise TypeError('Literal arguments must be of type str, int, bool, float or complex.')
if evaluated_args == args: