Skip to content

Commit 704fcb7

Browse files
Fix UnionType
1 parent d7a942d commit 704fcb7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

discord/app/commands.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,10 @@ 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) in (Union, getattr(types, "UnionType", Union)) # type: ignore
390+
return (
391+
getattr(annotation, '__origin__', None) is Union
392+
or annotation is getattr(types, "UnionType", Union)
393+
) # type: ignore
391394

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

discord/ext/commands/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,11 @@ def short_doc(self) -> str:
10201020
return ''
10211021

10221022
def _is_typing_optional(self, annotation: Union[T, Optional[T]]) -> TypeGuard[Optional[T]]:
1023-
return getattr(annotation, '__origin__', None) in (Union, getattr(types, "UnionType", Union)) and type(None) in annotation.__args__ # type: ignore
1024-
1023+
return (
1024+
(getattr(annotation, '__origin__', None) is Union
1025+
or annotation is getattr(types, "UnionType", Union))
1026+
and type(None) in annotation.__args__ # type: ignore
1027+
)
10251028
@property
10261029
def signature(self) -> str:
10271030
""":class:`str`: Returns a POSIX-like signature useful for help command output."""

0 commit comments

Comments
 (0)