mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue 24316: Fix types.coroutine() to accept objects from Cython
This commit is contained in:
parent
56fc614025
commit
c565cd5d1b
2 changed files with 72 additions and 26 deletions
|
@ -1196,11 +1196,39 @@ class CoroutineTests(unittest.TestCase):
|
|||
pass
|
||||
def bar(): pass
|
||||
|
||||
samples = [Foo, Foo(), bar, None, int, 1]
|
||||
samples = [None, 1, object()]
|
||||
for sample in samples:
|
||||
with self.assertRaisesRegex(TypeError, 'expects a generator'):
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
'types.coroutine.*expects a callable'):
|
||||
types.coroutine(sample)
|
||||
|
||||
def test_wrong_func(self):
|
||||
@types.coroutine
|
||||
def foo():
|
||||
pass
|
||||
@types.coroutine
|
||||
def gen():
|
||||
def _gen(): yield
|
||||
return _gen()
|
||||
|
||||
for sample in (foo, gen):
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
'callable wrapped .* non-coroutine'):
|
||||
sample()
|
||||
|
||||
def test_duck_coro(self):
|
||||
class CoroLike:
|
||||
def send(self): pass
|
||||
def throw(self): pass
|
||||
def close(self): pass
|
||||
def __await__(self): pass
|
||||
|
||||
coro = CoroLike()
|
||||
@types.coroutine
|
||||
def foo():
|
||||
return coro
|
||||
self.assertIs(coro, foo())
|
||||
|
||||
def test_genfunc(self):
|
||||
def gen():
|
||||
yield
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue