Skip to content

Commit

Permalink
[commands] Add support for types.Union to Greedy
Browse files Browse the repository at this point in the history
  • Loading branch information
bijij committed Aug 21, 2022
1 parent 6a6e261 commit 01bb7ec
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion discord/ext/commands/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
Union,
runtime_checkable,
)
import types

import discord

Expand Down Expand Up @@ -1021,8 +1022,11 @@ def __class_getitem__(cls, params: Union[Tuple[T], T]) -> Greedy[T]:
raise TypeError('Greedy[...] only takes a single argument')
converter = params[0]

origin = getattr(converter, '__origin__', None)
args = getattr(converter, '__args__', ())
if discord.utils.PY_310 and converter.__class__ is types.UnionType: # type: ignore
converter = Union[args] # type: ignore

origin = getattr(converter, '__origin__', None)

if not (callable(converter) or isinstance(converter, Converter) or origin is not None):
raise TypeError('Greedy[...] expects a type or a Converter instance.')
Expand Down

0 comments on commit 01bb7ec

Please sign in to comment.