Skip to content

Commit 5a1d34e

Browse files
committed
Fix Python 3.8 Union type checking.
1 parent f7f39e0 commit 5a1d34e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

discord_slash/model.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,16 @@ def from_type(cls, t: type):
483483
if issubclass(t, discord.abc.Role):
484484
return cls.ROLE
485485
# Here's the issue. Typechecking for a **Union** somewhat differs per version (from 3.6.8+)
486-
if (
487-
hasattr(typing, "_GenericAlias")
488-
and isinstance(t, typing._UnionGenericAlias) # noqa
489-
or not hasattr(typing, "_GenericAlias")
490-
and isinstance(t, typing._Union) # noqa
491-
):
492-
return cls.MENTIONABLE
486+
487+
if hasattr(typing, "_GenericAlias"): # 3.7 onwards
488+
if isinstance(t, typing._UnionGenericAlias): # noqa
489+
return cls.MENTIONABLE # 3.9+
490+
elif t.__origin__ is typing.Union: # 3.7-3.8
491+
return cls.MENTIONABLE
492+
else: # py 3.6
493+
if isinstance(t, typing._Union): # noqa
494+
return cls.MENTIONABLE
495+
493496
if issubclass(t, float):
494497
return cls.FLOAT
495498

0 commit comments

Comments
 (0)