Skip to content

Commit 4f75aaf

Browse files
committed
docs(docstrings): Add NumPy-style docstrings to async support code
why: Comply with project coding standards requiring NumPy docstrings what: - Add Parameters/Returns sections to _rst_content, _md_content helpers - Add docstrings to _Runner310.__init__, __enter__, __exit__ methods
1 parent 5a1dc02 commit 4f75aaf

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

src/doctest_docutils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,27 @@ def __init__(
5656
debug: bool | None = None,
5757
loop_factory: t.Callable[[], asyncio.AbstractEventLoop] | None = None,
5858
) -> None:
59+
"""Initialize the async runner.
60+
61+
Parameters
62+
----------
63+
debug : bool | None, optional
64+
Enable event loop debug mode, by default None
65+
loop_factory : Callable[[], AbstractEventLoop] | None, optional
66+
Factory function to create custom event loops, by default None
67+
"""
5968
self._debug = debug
6069
self._loop_factory = loop_factory
6170
self._loop: asyncio.AbstractEventLoop | None = None
6271

6372
def __enter__(self) -> _Runner310:
73+
"""Enter the context and create the event loop.
74+
75+
Returns
76+
-------
77+
_Runner310
78+
Self, for use in with-statement
79+
"""
6480
if self._loop_factory is None:
6581
loop = asyncio.new_event_loop()
6682
else:
@@ -84,6 +100,19 @@ def __exit__(
84100
exc_val: BaseException | None,
85101
exc_tb: t.Any,
86102
) -> None:
103+
"""Exit the context and clean up the event loop.
104+
105+
Cancels pending tasks, shuts down async generators, and closes the loop.
106+
107+
Parameters
108+
----------
109+
exc_type : type[BaseException] | None
110+
Exception type if an exception was raised
111+
exc_val : BaseException | None
112+
Exception instance if an exception was raised
113+
exc_tb : Any
114+
Traceback if an exception was raised
115+
"""
87116
loop = self._loop
88117
if loop is None:
89118
return

tests/test_async_doctest.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,18 @@ class AsyncDoctestFixture(t.NamedTuple):
3636

3737

3838
def _rst_content(body: str) -> str:
39-
"""Wrap doctest body in RST format."""
39+
"""Wrap doctest body in RST format.
40+
41+
Parameters
42+
----------
43+
body : str
44+
The doctest example code to embed
45+
46+
Returns
47+
-------
48+
str
49+
RST document with title and doctest body
50+
"""
4051
return f"""\
4152
Test
4253
====
@@ -46,7 +57,18 @@ def _rst_content(body: str) -> str:
4657

4758

4859
def _md_content(body: str) -> str:
49-
"""Wrap doctest body in Markdown format."""
60+
"""Wrap doctest body in Markdown format.
61+
62+
Parameters
63+
----------
64+
body : str
65+
The doctest example code to embed
66+
67+
Returns
68+
-------
69+
str
70+
Markdown document with heading and fenced code block
71+
"""
5072
return f"""\
5173
# Test
5274

0 commit comments

Comments
 (0)