Commit ca636eac authored by Guido van Rossum's avatar Guido van Rossum

Issue #25390: typing: Don't crash on Union[str, Pattern].

parent 460b3815
...@@ -317,6 +317,10 @@ class UnionTests(TestCase): ...@@ -317,6 +317,10 @@ class UnionTests(TestCase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
isinstance(42, Union[int, str]) 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): class TypeVarUnionTests(TestCase):
......
...@@ -487,6 +487,9 @@ class UnionMeta(TypingMeta): ...@@ -487,6 +487,9 @@ class UnionMeta(TypingMeta):
return Any return Any
if isinstance(t1, TypeVar): if isinstance(t1, TypeVar):
continue continue
if isinstance(t1, _TypeAlias):
# _TypeAlias is not a real class.
continue
if any(issubclass(t1, t2) if any(issubclass(t1, t2)
for t2 in all_params - {t1} if not isinstance(t2, TypeVar)): for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
all_params.remove(t1) all_params.remove(t1)
......
...@@ -45,6 +45,8 @@ Core and Builtins ...@@ -45,6 +45,8 @@ Core and Builtins
Library Library
------- -------
- Issue #25390: typing: Don't crash on Union[str, Pattern].
- Issue #25441: asyncio: Raise error from drain() when socket is closed. - Issue #25441: asyncio: Raise error from drain() when socket is closed.
- Issue #25410: Cleaned up and fixed minor bugs in C implementation of - Issue #25410: Cleaned up and fixed minor bugs in C implementation of
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment