aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Forbes <[email protected]>2018-08-10 16:47:42 -0500
committerRapptz <[email protected]>2018-08-22 21:53:47 -0400
commitef89d3aa227138e2589fa2eef181932ee264cc0e (patch)
tree6d5d73d2d395f808ae229fc679ea2ad713a816e8
parent[lint] Fix types used for __slots__ and __all__ (diff)
downloaddiscord.py-ef89d3aa227138e2589fa2eef181932ee264cc0e.tar.xz
discord.py-ef89d3aa227138e2589fa2eef181932ee264cc0e.zip
Add support for converters working with PEP-563
-rw-r--r--discord/ext/commands/core.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py
index a3198651..5cab6003 100644
--- a/discord/ext/commands/core.py
+++ b/discord/ext/commands/core.py
@@ -173,8 +173,20 @@ class Command:
self.description = inspect.cleandoc(kwargs.get('description', ''))
self.hidden = kwargs.get('hidden', False)
+
signature = inspect.signature(callback)
+ annotations = typing.get_type_hints(callback)
+
self.params = signature.parameters.copy()
+
+ # PEP-563 allows postponing evaluation of annotations with a __future__
+ # import. When postponed, Parameter.annotation will be a string and must
+ # be replaced with the real class from typing.get_type_hints() for the
+ # converters to work later on
+ for key, value in self.params.items():
+ if isinstance(value.annotation, str) and key in annotations:
+ self.params[key] = value.replace(annotation=annotations[key])
+
self.checks = kwargs.get('checks', [])
self.module = callback.__module__
self.ignore_extra = kwargs.get('ignore_extra', True)