[commands] Converter.convert is always a coroutine.

Along with this change comes with the removal of Converter.prepare and
adding two arguments to Converter.convert, the context and the argument.

I suppose an added benefit is that you don't have to do attribute
access since it's a local variable.
This commit is contained in:
Rapptz
2017-05-10 21:30:41 -04:00
parent 8ef984746a
commit d7478425ca
2 changed files with 83 additions and 78 deletions

View File

@ -202,13 +202,10 @@ class Command:
if inspect.isclass(converter) and issubclass(converter, converters.Converter):
instance = converter()
instance.prepare(ctx, argument)
ret = yield from discord.utils.maybe_coroutine(instance.convert)
ret = yield from instance.convert(ctx, argument)
return ret
if isinstance(converter, converters.Converter):
converter.prepare(ctx, argument)
ret = yield from discord.utils.maybe_coroutine(converter.convert)
elif isinstance(converter, converters.Converter):
ret = yield from converter.convert(ctx, argument)
return ret
return converter(argument)
@ -220,9 +217,6 @@ class Command:
converter = str if param.default is None else type(param.default)
else:
converter = str
elif not inspect.isclass(type(converter)):
raise discord.ClientException('Function annotation must be a type')
return converter
@asyncio.coroutine