summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2019-05-30 15:30:09 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-05-30 15:30:09 (GMT)
commit98ef92002ec289bf8086b0ef3d4f96c2589f4e68 (patch)
tree0c3420f69cef6e0c306af7508fdd06415b39a853 /Lib
parent25ee0c3bf10820496448e2886069f9c2794be7ac (diff)
downloadcpython-98ef92002ec289bf8086b0ef3d4f96c2589f4e68.zip
cpython-98ef92002ec289bf8086b0ef3d4f96c2589f4e68.tar.gz
cpython-98ef92002ec289bf8086b0ef3d4f96c2589f4e68.tar.bz2
bpo-36999: Add asyncio.Task.get_coro() (GH-13680)
https://bugs.python.org/issue36999
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/tasks.py3
-rw-r--r--Lib/test/test_asyncio/test_tasks.py10
2 files changed, 13 insertions, 0 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 78e7600..95e8560 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -152,6 +152,9 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
def _repr_info(self):
return base_tasks._task_repr_info(self)
+ def get_coro(self):
+ return self._coro
+
def get_name(self):
return self._name
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 114dd76..74ce259 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -2425,6 +2425,16 @@ class BaseTaskTests:
self.assertEqual(cvar.get(), -1)
+ def test_get_coro(self):
+ loop = asyncio.new_event_loop()
+ coro = coroutine_function()
+ try:
+ task = self.new_task(loop, coro)
+ loop.run_until_complete(task)
+ self.assertIs(task.get_coro(), coro)
+ finally:
+ loop.close()
+
def add_subclass_tests(cls):
BaseTask = cls.Task