[commands] Add support for Python 3.10 Union typing
This commit is contained in:
parent
1ecadf057e
commit
74d8ad2013
@ -35,6 +35,7 @@ import asyncio
|
|||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
import datetime
|
import datetime
|
||||||
|
import types
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
@ -104,6 +105,12 @@ def _evaluate_annotation(tp: Any, globals: Dict[str, Any], cache: Dict[str, Any]
|
|||||||
if hasattr(tp, '__args__'):
|
if hasattr(tp, '__args__'):
|
||||||
implicit_str = True
|
implicit_str = True
|
||||||
args = tp.__args__
|
args = tp.__args__
|
||||||
|
if not hasattr(tp, '__origin__'):
|
||||||
|
if PY_310 and tp.__class__ is types.Union:
|
||||||
|
converted = Union[args] # type: ignore
|
||||||
|
return _evaluate_annotation(converted, globals, cache)
|
||||||
|
|
||||||
|
return tp
|
||||||
if tp.__origin__ is Union:
|
if tp.__origin__ is Union:
|
||||||
try:
|
try:
|
||||||
if args.index(type(None)) != len(args) - 1:
|
if args.index(type(None)) != len(args) - 1:
|
||||||
@ -136,7 +143,7 @@ def resolve_annotation(annotation: Any, globalns: Dict[str, Any], cache: Dict[st
|
|||||||
annotation = ForwardRef(annotation)
|
annotation = ForwardRef(annotation)
|
||||||
return _evaluate_annotation(annotation, globalns, cache)
|
return _evaluate_annotation(annotation, globalns, cache)
|
||||||
|
|
||||||
def get_signature_parameters(function) -> Dict[str, inspect.Parameter]:
|
def get_signature_parameters(function: types.FunctionType) -> Dict[str, inspect.Parameter]:
|
||||||
globalns = function.__globals__
|
globalns = function.__globals__
|
||||||
signature = inspect.signature(function)
|
signature = inspect.signature(function)
|
||||||
params = {}
|
params = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user