bpo-36999: Add asyncio.Task.get_coro() by agronholm · Pull Request #13680 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Doc/library/asyncio-task.rst
3 changes: 3 additions & 0 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def __del__(self):
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

Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,16 @@ async def main():

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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add the ``asyncio.Task.get_coro()`` method to publicly expose the tasks's
coroutine object.
13 changes: 13 additions & 0 deletions Modules/_asynciomodule.c
19 changes: 18 additions & 1 deletion Modules/clinic/_asynciomodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.