@@ -650,6 +650,13 @@ def from_datatype(cls, datatype):
650
650
else :
651
651
raise TypeError ("Invalid usage of typing.Union" )
652
652
653
+ py_3_10_union_type = hasattr (types , "UnionType" ) and isinstance (datatype , types .UnionType )
654
+
655
+ if py_3_10_union_type or getattr (datatype , "__origin__" , None ) is Union :
656
+ # Python 3.10+ "|" operator or typing.Union has been used. The __args__ attribute is a tuple of the types.
657
+ # Type checking fails for this case, so ignore it.
658
+ return cls .from_datatype (datatype .__args__ ) # type: ignore
659
+
653
660
if datatype .__name__ in ["Member" , "User" ]:
654
661
return cls .user
655
662
if datatype .__name__ in [
@@ -669,11 +676,6 @@ def from_datatype(cls, datatype):
669
676
if datatype .__name__ == "Mentionable" :
670
677
return cls .mentionable
671
678
672
- if isinstance (datatype , types .UnionType ) or getattr (datatype , "__origin__" , None ) is Union :
673
- # Python 3.10+ "|" operator or typing.Union has been used. The __args__ attribute is a tuple of the types.
674
- # Type checking fails for this case, so ignore it.
675
- return cls .from_datatype (datatype .__args__ ) # type: ignore
676
-
677
679
if issubclass (datatype , str ):
678
680
return cls .string
679
681
if issubclass (datatype , bool ):
0 commit comments