diff options
| author | Rapptz <[email protected]> | 2021-04-11 02:11:24 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-04-11 02:11:24 -0400 |
| commit | 74d8ad2013314b8ea11cdd8fe73af72ad76e969f (patch) | |
| tree | e76f5282b4f08be0f0bf47574f35541dcc995421 /discord/ext | |
| parent | [commands] Fix errors with cooldown mappings (diff) | |
| download | discord.py-74d8ad2013314b8ea11cdd8fe73af72ad76e969f.tar.xz discord.py-74d8ad2013314b8ea11cdd8fe73af72ad76e969f.zip | |
[commands] Add support for Python 3.10 Union typing
Diffstat (limited to 'discord/ext')
| -rw-r--r-- | discord/ext/commands/core.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 215c89b1..7b54717f 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -35,6 +35,7 @@ import asyncio import functools import inspect import datetime +import types import sys import discord @@ -104,6 +105,12 @@ def _evaluate_annotation(tp: Any, globals: Dict[str, Any], cache: Dict[str, Any] if hasattr(tp, '__args__'): implicit_str = True 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: try: 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) 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__ signature = inspect.signature(function) params = {} |