mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 18:59:09 +00:00
Add support for converters working with PEP-563
This commit is contained in:
parent
c557ee33ca
commit
ef89d3aa22
@ -173,8 +173,20 @@ class Command:
|
|||||||
|
|
||||||
self.description = inspect.cleandoc(kwargs.get('description', ''))
|
self.description = inspect.cleandoc(kwargs.get('description', ''))
|
||||||
self.hidden = kwargs.get('hidden', False)
|
self.hidden = kwargs.get('hidden', False)
|
||||||
|
|
||||||
signature = inspect.signature(callback)
|
signature = inspect.signature(callback)
|
||||||
|
annotations = typing.get_type_hints(callback)
|
||||||
|
|
||||||
self.params = signature.parameters.copy()
|
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.checks = kwargs.get('checks', [])
|
||||||
self.module = callback.__module__
|
self.module = callback.__module__
|
||||||
self.ignore_extra = kwargs.get('ignore_extra', True)
|
self.ignore_extra = kwargs.get('ignore_extra', True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user