Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59136cc

Browse files
author
Guido van Rossum
committed
Issue #25390: typing: Don't crash on Union[str, Pattern]. (Merge 3.5->3.6)
2 parents 77b3d48 + ca636ea commit 59136cc

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/test/test_typing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ def test_union_instance_type_error(self):
317317
with self.assertRaises(TypeError):
318318
isinstance(42, Union[int, str])
319319

320+
def test_union_str_pattern(self):
321+
# Shouldn't crash; see http://bugs.python.org/issue25390
322+
A = Union[str, Pattern]
323+
320324

321325
class TypeVarUnionTests(TestCase):
322326

Lib/typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ def __new__(cls, name, bases, namespace, parameters=None, _root=False):
487487
return Any
488488
if isinstance(t1, TypeVar):
489489
continue
490+
if isinstance(t1, _TypeAlias):
491+
# _TypeAlias is not a real class.
492+
continue
490493
if any(issubclass(t1, t2)
491494
for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
492495
all_params.remove(t1)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Core and Builtins
6363
Library
6464
-------
6565

66+
- Issue #25390: typing: Don't crash on Union[str, Pattern].
67+
6668
- Issue #25441: asyncio: Raise error from drain() when socket is closed.
6769

6870
- Issue #25410: Cleaned up and fixed minor bugs in C implementation of

0 commit comments

Comments
 (0)