mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
Issue #24635: Fixed flakiness in test_typing.py.
This commit is contained in:
parent
874dbe895d
commit
647bae6c52
3 changed files with 27 additions and 8 deletions
|
|
@ -436,12 +436,14 @@ def test_cannot_instantiate(self):
|
|||
c()
|
||||
|
||||
def test_callable_instance_works(self):
|
||||
f = lambda: None
|
||||
def f():
|
||||
pass
|
||||
assert isinstance(f, Callable)
|
||||
assert not isinstance(None, Callable)
|
||||
|
||||
def test_callable_instance_type_error(self):
|
||||
f = lambda: None
|
||||
def f():
|
||||
pass
|
||||
with self.assertRaises(TypeError):
|
||||
assert isinstance(f, Callable[[], None])
|
||||
with self.assertRaises(TypeError):
|
||||
|
|
@ -674,7 +676,9 @@ def test_type_erasure(self):
|
|||
T = TypeVar('T')
|
||||
|
||||
class Node(Generic[T]):
|
||||
def __init__(self, label: T, left: 'Node[T]' = None, right: 'Node[T]' = None):
|
||||
def __init__(self, label: T,
|
||||
left: 'Node[T]' = None,
|
||||
right: 'Node[T]' = None):
|
||||
self.label = label # type: T
|
||||
self.left = left # type: Optional[Node[T]]
|
||||
self.right = right # type: Optional[Node[T]]
|
||||
|
|
@ -933,9 +937,16 @@ def test_hashable(self):
|
|||
assert not isinstance([], typing.Hashable)
|
||||
|
||||
def test_iterable(self):
|
||||
assert isinstance([], typing.Iterable)
|
||||
# Due to ABC caching, the second time takes a separate code
|
||||
# path and could fail. So call this a few times.
|
||||
assert isinstance([], typing.Iterable)
|
||||
assert isinstance([], typing.Iterable)
|
||||
assert isinstance([], typing.Iterable[int])
|
||||
assert not isinstance(42, typing.Iterable)
|
||||
# Just in case, also test issubclass() a few times.
|
||||
assert issubclass(list, typing.Iterable)
|
||||
assert issubclass(list, typing.Iterable)
|
||||
|
||||
def test_iterator(self):
|
||||
it = iter([])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue