File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments