From 6f32b2a1746c89d1138b10a6bf74955649e62c08 Mon Sep 17 00:00:00 2001 From: florimondmanca Date: Sat, 12 Oct 2019 14:46:32 +0200 Subject: [PATCH] Display async keyword in front of async functions/methods --- mkautodoc/extension.py | 3 +++ tests/mocklib/mocklib.py | 6 ++++++ tests/test_extension.py | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/mkautodoc/extension.py b/mkautodoc/extension.py index db64fd4..04c92ae 100644 --- a/mkautodoc/extension.py +++ b/mkautodoc/extension.py @@ -182,6 +182,9 @@ def render_signature( if inspect.isclass(item): qualifier_elem = etree.SubElement(signature_elem, "em") qualifier_elem.text = "class " + elif inspect.iscoroutinefunction(item): + qualifier_elem = etree.SubElement(signature_elem, "em") + qualifier_elem.text = "async " name_elem = etree.SubElement(signature_elem, "code") if module_string: diff --git a/tests/mocklib/mocklib.py b/tests/mocklib/mocklib.py index 7b70eea..f41bb9b 100644 --- a/tests/mocklib/mocklib.py +++ b/tests/mocklib/mocklib.py @@ -24,3 +24,9 @@ def example_property(self): """ This is a property with a *docstring*. """ + + +async def example_async_function(): + """ + This is a coroutine function as can be seen by the *async* keyword. + """ diff --git a/tests/test_extension.py b/tests/test_extension.py index a9db6d0..854d3ee 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -18,6 +18,18 @@ def test_docstring(): ] +def test_async_function(): + content = """ +::: mocklib.example_async_function +""" + output = markdown.markdown(content, extensions=["mkautodoc"]) + assert output.splitlines() == [ + '
', + '
async mocklib.example_async_function()
', + "
", + ] + + def test_members(): content = """ # Example