summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/coroutines.py
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-05-29 04:55:27 (GMT)
committerGitHub <noreply@github.com>2018-05-29 04:55:27 (GMT)
commite151f83deab9819fb8d9dfc59f9baa4a7273226c (patch)
tree084d530574d6a02f2377438e89a90524bbad8a8e /Lib/asyncio/coroutines.py
parent7593b8a5075ff45d71be9f62980be6a9c005afa9 (diff)
downloadcpython-e151f83deab9819fb8d9dfc59f9baa4a7273226c.zip
cpython-e151f83deab9819fb8d9dfc59f9baa4a7273226c.tar.gz
cpython-e151f83deab9819fb8d9dfc59f9baa4a7273226c.tar.bz2
bpo-33672: Fix Task.__repr__ crash with Cython's bogus coroutines (GH-7180)
[3.6 backport of 989b9e0]
Diffstat (limited to 'Lib/asyncio/coroutines.py')
-rw-r--r--Lib/asyncio/coroutines.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/Lib/asyncio/coroutines.py b/Lib/asyncio/coroutines.py
index 520a309..a9022f9 100644
--- a/Lib/asyncio/coroutines.py
+++ b/Lib/asyncio/coroutines.py
@@ -310,18 +310,25 @@ def _format_coroutine(coro):
if coro_name is None:
coro_name = events._format_callback(func, (), {})
- try:
- coro_code = coro.gi_code
- except AttributeError:
+ coro_code = None
+ if hasattr(coro, 'cr_code') and coro.cr_code:
coro_code = coro.cr_code
+ elif hasattr(coro, 'gi_code') and coro.gi_code:
+ coro_code = coro.gi_code
- try:
- coro_frame = coro.gi_frame
- except AttributeError:
+ coro_frame = None
+ if hasattr(coro, 'cr_frame') and coro.cr_frame:
coro_frame = coro.cr_frame
+ elif hasattr(coro, 'gi_frame') and coro.gi_frame:
+ coro_frame = coro.gi_frame
+
+ filename = '<empty co_filename>'
+ if coro_code and coro_code.co_filename:
+ filename = coro_code.co_filename
- filename = coro_code.co_filename
lineno = 0
+ coro_repr = coro_name
+
if (isinstance(coro, CoroWrapper) and
not inspect.isgeneratorfunction(coro.func) and
coro.func is not None):
@@ -338,7 +345,7 @@ def _format_coroutine(coro):
lineno = coro_frame.f_lineno
coro_repr = ('%s running at %s:%s'
% (coro_name, filename, lineno))
- else:
+ elif coro_code:
lineno = coro_code.co_firstlineno
coro_repr = ('%s done, defined at %s:%s'
% (coro_name, filename, lineno))