From: Guido van Rossum Date: Mon, 19 Oct 2015 21:55:47 +0000 (-0700) Subject: Issue #25390: typing: Don't crash on Union[str, Pattern]. X-Git-Tag: v3.5.1rc1~145 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ca636eac88c2653fafedf063b7cac4924330e966;p=thirdparty%2FPython%2Fcpython.git Issue #25390: typing: Don't crash on Union[str, Pattern]. --- diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 1461cfbe4875..a74ec079b56f 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -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): diff --git a/Lib/typing.py b/Lib/typing.py index 1a4982ead9a3..d900036e5144 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index 658c9189324c..70b03ee12efe 100644 --- 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