diff options
| author | Rapptz <[email protected]> | 2018-07-20 18:01:48 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2018-07-20 18:01:48 -0400 |
| commit | 69ca675ca057f8bbd961562eefced97026e5d671 (patch) | |
| tree | a964151f906571bde7544e81a6f166e95765f3ca | |
| parent | [commands] Add documentation for BadUnionArgument (diff) | |
| download | discord.py-69ca675ca057f8bbd961562eefced97026e5d671.tar.xz discord.py-69ca675ca057f8bbd961562eefced97026e5d671.zip | |
[commands] Fix typing.Union converters for 3.7
Guido please don't break this
| -rw-r--r-- | discord/ext/commands/core.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 7a03feb3..4035035f 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -257,18 +257,23 @@ class Command: if converter is bool: return _convert_to_bool(argument) - if type(converter) is typing._Union: - errors = [] - for conv in converter.__args__: - 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 - raise BadUnionArgument(param, converter.__args__, errors) + try: + origin = converter.__origin__ + except AttributeError: + pass + else: + if origin is typing.Union: + errors = [] + for conv in converter.__args__: + 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 + raise BadUnionArgument(param, converter.__args__, errors) return await self._actual_conversion(ctx, converter, argument, param) |