[commands] Add support for types.Union to Greedy

This commit is contained in:
Josh 2022-08-22 08:26:32 +10:00 committed by GitHub
parent 6a6e261523
commit 01bb7ecb79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,7 @@ from typing import (
Union,
runtime_checkable,
)
import types
import discord
@ -1021,8 +1022,11 @@ class Greedy(List[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.')