Skip to content

Commit 123223c

Browse files
committed
Remove typing._UnionGenericAlias for attr checks to reduce import errors.
1 parent 5a1d34e commit 123223c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

discord_slash/model.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,13 @@ def from_type(cls, t: type):
482482
return cls.CHANNEL
483483
if issubclass(t, discord.abc.Role):
484484
return cls.ROLE
485-
# Here's the issue. Typechecking for a **Union** somewhat differs per version (from 3.6.8+)
486-
487485
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
486+
# Easier than imports
487+
if (
488+
t.__origin__ is not None and t.__origin__ is typing.Union
489+
): # proven in 3.7.8+, 3.8.6+, 3.9+ definitively
491490
return cls.MENTIONABLE
492-
else: # py 3.6
491+
if not hasattr(typing, "_GenericAlias"): # py 3.6
493492
if isinstance(t, typing._Union): # noqa
494493
return cls.MENTIONABLE
495494

0 commit comments

Comments
 (0)