bpo-33672: Fix Task.__repr__ crash with Cython's bogus coroutines (GH-7161)

This commit is contained in:
Yury Selivanov 2018-05-28 16:27:34 -04:00 committed by GitHub
parent 8267ea2e84
commit 989b9e0e6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 39 deletions

View file

@ -2784,11 +2784,21 @@ class HandleTests(test_utils.TestCase):
coro.cr_running = True
self.assertEqual(coroutines._format_coroutine(coro), 'BBB() running')
coro.__name__ = coro.__qualname__ = None
self.assertEqual(coroutines._format_coroutine(coro),
'<CoroLike without __name__>() running')
coro = CoroLike()
coro.__qualname__ = 'CoroLike'
# Some coroutines might not have '__name__', such as
# built-in async_gen.asend().
self.assertEqual(coroutines._format_coroutine(coro), 'CoroLike()')
coro = CoroLike()
coro.__qualname__ = 'AAA'
coro.cr_code = None
self.assertEqual(coroutines._format_coroutine(coro), 'AAA()')
class TimerTests(unittest.TestCase):