@@ -650,6 +650,13 @@ def from_datatype(cls, datatype):
650650 else :
651651 raise TypeError ("Invalid usage of typing.Union" )
652652
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+
653660 if datatype .__name__ in ["Member" , "User" ]:
654661 return cls .user
655662 if datatype .__name__ in [
@@ -669,11 +676,6 @@ def from_datatype(cls, datatype):
669676 if datatype .__name__ == "Mentionable" :
670677 return cls .mentionable
671678
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-
677679 if issubclass (datatype , str ):
678680 return cls .string
679681 if issubclass (datatype , bool ):
0 commit comments