Skip to content

Commit d7a942d

Browse files
Support python 3.10 union
1 parent 0d1b9a4 commit d7a942d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

discord/app/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from __future__ import annotations
2626

2727
import asyncio
28+
import types
2829
from discord.types.channel import TextChannel, VoiceChannel
2930
import functools
3031
import inspect
@@ -336,7 +337,6 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
336337
def parse_options(self, params) -> List[Option]:
337338
final_options = []
338339

339-
params = self._get_signature_parameters()
340340
if list(params.items())[0][0] == "self":
341341
temp = list(params.items())
342342
temp.pop(0)
@@ -387,7 +387,7 @@ def parse_options(self, params) -> List[Option]:
387387
return final_options
388388

389389
def _is_typing_union(self, annotation):
390-
return getattr(annotation, "__origin__", None) is Union # type: ignore
390+
return getattr(annotation, "__origin__", None) in (Union, getattr(types, "UnionType", Union)) # type: ignore
391391

392392
def _is_typing_optional(self, annotation):
393393
return self._is_typing_union(annotation) and type(None) in annotation.__args__ # type: ignore

discord/ext/commands/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import functools
4545
import inspect
4646
import datetime
47+
import types
4748

4849
import discord
4950

@@ -1019,7 +1020,7 @@ def short_doc(self) -> str:
10191020
return ''
10201021

10211022
def _is_typing_optional(self, annotation: Union[T, Optional[T]]) -> TypeGuard[Optional[T]]:
1022-
return getattr(annotation, '__origin__', None) is Union and type(None) in annotation.__args__ # type: ignore
1023+
return getattr(annotation, '__origin__', None) in (Union, getattr(types, "UnionType", Union)) and type(None) in annotation.__args__ # type: ignore
10231024

10241025
@property
10251026
def signature(self) -> str:

0 commit comments

Comments
 (0)