File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -262,8 +262,12 @@ def _format_coroutine(coro):
262
262
assert iscoroutine (coro )
263
263
264
264
if not hasattr (coro , 'cr_code' ) and not hasattr (coro , 'gi_code' ):
265
- # Most likely a Cython coroutine.
266
- coro_name = getattr (coro , '__qualname__' , coro .__name__ )
265
+ # Most likely a built-in type or a Cython coroutine.
266
+
267
+ # Built-in types might not have __qualname__ or __name__.
268
+ coro_name = getattr (
269
+ coro , '__qualname__' ,
270
+ getattr (coro , '__name__' , type (coro ).__name__ ))
267
271
coro_name = '{}()' .format (coro_name )
268
272
269
273
running = False
Original file line number Diff line number Diff line change @@ -2384,8 +2384,6 @@ def test_coroutine_like_object_debug_formatting(self):
2384
2384
# (such as ones compiled with Cython).
2385
2385
2386
2386
class Coro :
2387
- __name__ = 'AAA'
2388
-
2389
2387
def send (self , v ):
2390
2388
pass
2391
2389
@@ -2399,6 +2397,7 @@ def __await__(self):
2399
2397
pass
2400
2398
2401
2399
coro = Coro ()
2400
+ coro .__name__ = 'AAA'
2402
2401
self .assertTrue (asyncio .iscoroutine (coro ))
2403
2402
self .assertEqual (coroutines ._format_coroutine (coro ), 'AAA()' )
2404
2403
@@ -2408,6 +2407,11 @@ def __await__(self):
2408
2407
coro .cr_running = True
2409
2408
self .assertEqual (coroutines ._format_coroutine (coro ), 'BBB() running' )
2410
2409
2410
+ coro = Coro ()
2411
+ # Some coroutines might not have '__name__', such as
2412
+ # built-in async_gen.asend().
2413
+ self .assertEqual (coroutines ._format_coroutine (coro ), 'Coro()' )
2414
+
2411
2415
2412
2416
class TimerTests (unittest .TestCase ):
2413
2417
You can’t perform that action at this time.
0 commit comments