[Python-checkins] cpython (3.5): Issue #25390: typing: Don't crash on Union[str, Pattern].

guido.van.rossum python-checkins at python.org
Mon Oct 19 17:56:43 EDT 2015


https://hg.python.org/cpython/rev/955d3faf727a
changeset:   98800:955d3faf727a
branch:      3.5
parent:      98798:43c63dd2f383
user:        Guido van Rossum <guido at python.org>
date:        Mon Oct 19 14:55:47 2015 -0700
summary:
  Issue #25390: typing: Don't crash on Union[str, Pattern].

files:
  Lib/test/test_typing.py |  4 ++++
  Lib/typing.py           |  3 +++
  Misc/NEWS               |  2 ++
  3 files changed, 9 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -317,6 +317,10 @@
         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):
 
diff --git a/Lib/typing.py b/Lib/typing.py
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -487,6 +487,9 @@
                 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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -45,6 +45,8 @@
 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

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list