[3.10] bpo-44654: Refactor and clean up the union type implementation (GH-27196) (GH-27219)

(cherry picked from commit 0fd27375cabd12e68a2f12cfeca11a2d5043429e)
diff --git a/Lib/typing.py b/Lib/typing.py
index 1823cb8..508f4b6 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -1181,7 +1181,7 @@ def copy_with(self, params):
         return Union[params]
 
     def __eq__(self, other):
-        if not isinstance(other, _UnionGenericAlias):
+        if not isinstance(other, (_UnionGenericAlias, types.Union)):
             return NotImplemented
         return set(self.__args__) == set(other.__args__)