]> granicus.if.org Git - python/commitdiff
Issue #25390: typing: Don't crash on Union[str, Pattern].
authorGuido van Rossum <guido@python.org>
Mon, 19 Oct 2015 21:55:47 +0000 (14:55 -0700)
committerGuido van Rossum <guido@python.org>
Mon, 19 Oct 2015 21:55:47 +0000 (14:55 -0700)
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS

index 1461cfbe4875b209d277a337458c2c5029c136d6..a74ec079b56f9b92601c45004f9fb746b42e3302 100644 (file)
@@ -317,6 +317,10 @@ class UnionTests(TestCase):
         with self.assertRaises(TypeError):
             isinstance(42, Union[int, str])
 
+    def test_union_str_pattern(self):
+        # Shouldn't crash; see http://bugs.python.org/issue25390
+        A = Union[str, Pattern]
+
 
 class TypeVarUnionTests(TestCase):
 
index 1a4982ead9a3e49a8e3c8748b92dcf85a12fcd7f..d900036e5144d293bd5f9e287c42396ac302f460 100644 (file)
@@ -487,6 +487,9 @@ class UnionMeta(TypingMeta):
                 return Any
             if isinstance(t1, TypeVar):
                 continue
+            if isinstance(t1, _TypeAlias):
+                # _TypeAlias is not a real class.
+                continue
             if any(issubclass(t1, t2)
                    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
                 all_params.remove(t1)
index 658c9189324c6fc292d41c250e1e69eb747e2eea..70b03ee12efe1d526469af6da4d20674b6c9b3c8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -45,6 +45,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #25390: typing: Don't crash on Union[str, Pattern].
+
 - Issue #25441: asyncio: Raise error from drain() when socket is closed.
 
 - Issue #25410: Cleaned up and fixed minor bugs in C implementation of