changeset: 98801:04314479af0b parent: 98799:7947f43a1a87 parent: 98800:955d3faf727a user: Guido van Rossum date: Mon Oct 19 14:56:25 2015 -0700 files: Lib/test/test_typing.py Lib/typing.py Misc/NEWS description: Issue #25390: typing: Don't crash on Union[str, Pattern]. (Merge 3.5->3.6) diff -r 7947f43a1a87 -r 04314479af0b Lib/test/test_typing.py --- a/Lib/test/test_typing.py Mon Oct 19 13:19:08 2015 -0700 +++ b/Lib/test/test_typing.py Mon Oct 19 14:56:25 2015 -0700 @@ -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 -r 7947f43a1a87 -r 04314479af0b Lib/typing.py --- a/Lib/typing.py Mon Oct 19 13:19:08 2015 -0700 +++ b/Lib/typing.py Mon Oct 19 14:56:25 2015 -0700 @@ -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 -r 7947f43a1a87 -r 04314479af0b Misc/NEWS --- a/Misc/NEWS Mon Oct 19 13:19:08 2015 -0700 +++ b/Misc/NEWS Mon Oct 19 14:56:25 2015 -0700 @@ -63,6 +63,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