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
18 changes: 15 additions & 3 deletions Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,12 @@ def docroutine(self, object, name=None, mod=None,
else:
note = ' unbound %s method' % self.classlink(imclass,mod)

if (inspect.iscoroutinefunction(object) or
inspect.isasyncgenfunction(object)):
asyncqualifier = 'async '
else:
asyncqualifier = ''

if name == realname:
title = '<a name="%s"><strong>%s</strong></a>' % (anchor, realname)
else:
Expand Down Expand Up @@ -975,8 +981,8 @@ def docroutine(self, object, name=None, mod=None,
if not argspec:
argspec = '(...)'

decl = title + self.escape(argspec) + (note and self.grey(
'<font face="helvetica, arial">%s</font>' % note))
decl = asyncqualifier + title + self.escape(argspec) + (note and
self.grey('<font face="helvetica, arial">%s</font>' % note))

if skipdocs:
return '<dl><dt>%s</dt></dl>\n' % decl
Expand Down Expand Up @@ -1376,6 +1382,12 @@ def docroutine(self, object, name=None, mod=None, cl=None):
else:
note = ' unbound %s method' % classname(imclass,mod)

if (inspect.iscoroutinefunction(object) or
inspect.isasyncgenfunction(object)):
asyncqualifier = 'async '
else:
asyncqualifier = ''

if name == realname:
title = self.bold(realname)
else:
Expand All @@ -1399,7 +1411,7 @@ def docroutine(self, object, name=None, mod=None, cl=None):
argspec = argspec[1:-1] # remove parentheses
if not argspec:
argspec = '(...)'
decl = title + argspec + note
decl = asyncqualifier + title + argspec + note

if skipdocs:
return decl + '\n'
Expand Down
23 changes: 23 additions & 0 deletions Lib/test/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,29 @@ class X:
Custom descriptor
""")

def test_async_annotation(self):
async def coro_function(ign) -> int:
return 1

text = pydoc.plain(pydoc.plaintext.document(coro_function))
self.assertIn('async coro_function', text)

html = pydoc.HTMLDoc().document(coro_function)
self.assertIn(
'async <a name="-coro_function"><strong>coro_function',
html)

def test_async_generator_annotation(self):
async def an_async_generator():
yield 1

text = pydoc.plain(pydoc.plaintext.document(an_async_generator))
self.assertIn('async an_async_generator', text)

html = pydoc.HTMLDoc().document(an_async_generator)
self.assertIn(
'async <a name="-an_async_generator"><strong>an_async_generator',
html)

class PydocServerTest(unittest.TestCase):
"""Tests for pydoc._start_server"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
builtins.help() now prefixes `async` for async functions