Remove typing._UnionGenericAlias for attr checks to reduce import errors.
@@ -482,14 +482,13 @@ class SlashCommandOptionType(IntEnum):
return cls.CHANNEL
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"): # 3.7 onwards
- if isinstance(t, typing._UnionGenericAlias): # noqa
- return cls.MENTIONABLE # 3.9+
- elif t.__origin__ is typing.Union: # 3.7-3.8
+ # Easier than imports
+ if (
+ t.__origin__ is not None and t.__origin__ is typing.Union
+ ): # proven in 3.7.8+, 3.8.6+, 3.9+ definitively
return cls.MENTIONABLE
- else: # py 3.6
+ if not hasattr(typing, "_GenericAlias"): # py 3.6
if isinstance(t, typing._Union): # noqa
return cls.MENTIONABLE
