mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
[commands] Add support for types.Union to Greedy
This commit is contained in:
parent
6a6e261523
commit
01bb7ecb79
@ -43,6 +43,7 @@ from typing import (
|
|||||||
Union,
|
Union,
|
||||||
runtime_checkable,
|
runtime_checkable,
|
||||||
)
|
)
|
||||||
|
import types
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
@ -1021,8 +1022,11 @@ class Greedy(List[T]):
|
|||||||
raise TypeError('Greedy[...] only takes a single argument')
|
raise TypeError('Greedy[...] only takes a single argument')
|
||||||
converter = params[0]
|
converter = params[0]
|
||||||
|
|
||||||
origin = getattr(converter, '__origin__', None)
|
|
||||||
args = getattr(converter, '__args__', ())
|
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):
|
if not (callable(converter) or isinstance(converter, Converter) or origin is not None):
|
||||||
raise TypeError('Greedy[...] expects a type or a Converter instance.')
|
raise TypeError('Greedy[...] expects a type or a Converter instance.')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user