Fix Python 3.8 Union type checking.
@@ -483,13 +483,16 @@ class SlashCommandOptionType(IntEnum):
if issubclass(t, discord.abc.Role):
return cls.ROLE
# Here's the issue. Typechecking for a **Union** somewhat differs per version (from 3.6.8+)
- if (
- hasattr(typing, "_GenericAlias")
- and isinstance(t, typing._UnionGenericAlias) # noqa
- or not hasattr(typing, "_GenericAlias")
- and isinstance(t, typing._Union) # noqa
- ):
+
+ if hasattr(typing, "_GenericAlias"): # 3.7 onwards
+ if isinstance(t, typing._UnionGenericAlias): # noqa
+ return cls.MENTIONABLE # 3.9+
+ elif t.__origin__ is typing.Union: # 3.7-3.8
return cls.MENTIONABLE
+ else: # py 3.6
+ if isinstance(t, typing._Union): # noqa
+ return cls.MENTIONABLE
+
if issubclass(t, float):
return cls.FLOAT
