[commands] Fix typing.Union converters for 3.7

Guido please don't break this
This commit is contained in:
Rapptz 2018-07-20 18:01:48 -04:00
parent 52767cf315
commit 69ca675ca0

View File

@ -257,18 +257,23 @@ class Command:
if converter is bool: if converter is bool:
return _convert_to_bool(argument) return _convert_to_bool(argument)
if type(converter) is typing._Union: try:
errors = [] origin = converter.__origin__
for conv in converter.__args__: except AttributeError:
try: pass
value = await self._actual_conversion(ctx, conv, argument, param) else:
except CommandError as e: if origin is typing.Union:
errors.append(e) errors = []
else: for conv in converter.__args__:
return value try:
value = await self._actual_conversion(ctx, conv, argument, param)
except CommandError as e:
errors.append(e)
else:
return value
# if we're here, then we failed all the converters # if we're here, then we failed all the converters
raise BadUnionArgument(param, converter.__args__, errors) raise BadUnionArgument(param, converter.__args__, errors)
return await self._actual_conversion(ctx, converter, argument, param) return await self._actual_conversion(ctx, converter, argument, param)