Skip to content

Commit ffaadc4

Browse files
authored
Merge pull request #276 from DeltaXWizard/master
Fix Python 3.8 Union type checking.
2 parents 18868bf + a560796 commit ffaadc4

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

discord_slash/model.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,14 +490,16 @@ def from_type(cls, t: type):
490490
return cls.CHANNEL
491491
if issubclass(t, discord.abc.Role):
492492
return cls.ROLE
493-
# Here's the issue. Typechecking for a **Union** somewhat differs per version (from 3.6.8+)
494-
if (
495-
hasattr(typing, "_GenericAlias")
496-
and isinstance(t, typing._UnionGenericAlias) # noqa
497-
or not hasattr(typing, "_GenericAlias")
498-
and isinstance(t, typing._Union) # noqa
499-
):
500-
return cls.MENTIONABLE
493+
if hasattr(typing, "_GenericAlias"): # 3.7 onwards
494+
# Easier than imports
495+
if hasattr(t, "__origin__"):
496+
if t.__origin__ is typing.Union:
497+
# proven in 3.7.8+, 3.8.6+, 3.9+ definitively
498+
return cls.MENTIONABLE
499+
if not hasattr(typing, "_GenericAlias"): # py 3.6
500+
if isinstance(t, typing._Union): # noqa
501+
return cls.MENTIONABLE
502+
501503
if issubclass(t, float):
502504
return cls.FLOAT
503505

0 commit comments

Comments
 (0)