Skip to content

Commit d1136ea

Browse files
ERosendokernc
authored andcommitted
ENH: Handle union type expressions for Google style docstrings
1 parent 84ee28b commit d1136ea

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

pdoc/html_helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,14 @@ def googledoc_sections(match):
248248
section = section.title()
249249
if section in ('Args', 'Attributes'):
250250
body = re.compile(
251-
r'^([\w*]+)(?: \(([\w.,=\[\] -]+)\))?: '
251+
r'^([\w*]+)(?: \(([\w.,=|\[\] -]+)\))?: '
252252
r'((?:.*)(?:\n(?: {2,}.*|$))*)', re.MULTILINE).sub(
253253
lambda m: _ToMarkdown._deflist(*_ToMarkdown._fix_indent(*m.groups())),
254254
inspect.cleandoc(f'\n{body}')
255255
)
256256
elif section in ('Returns', 'Yields', 'Raises', 'Warns'):
257257
body = re.compile(
258-
r'^()([\w.,\[\] ]+): '
258+
r'^()([\w.,|\[\] ]+): '
259259
r'((?:.*)(?:\n(?: {2,}.*|$))*)', re.MULTILINE).sub(
260260
lambda m: _ToMarkdown._deflist(*_ToMarkdown._fix_indent(*m.groups())),
261261
inspect.cleandoc(f'\n{body}')

pdoc/test/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,8 @@ def test_google(self):
14571457
<dd>Description of arg1</dd>
14581458
<dt><strong><code>arg2</code></strong> :&ensp;<code>str</code> or <code>int</code></dt>
14591459
<dd>Description of arg2</dd>
1460+
<dt><strong><code>arg3</code></strong> :&ensp;<code>str | None</code></dt>
1461+
<dd>Description of arg3</dd>
14601462
<dt><strong><code>test_sequence</code></strong></dt>
14611463
<dd>
14621464
<p>2-dim numpy array of real numbers, size: N * D
@@ -1484,6 +1486,11 @@ def test_google(self):
14841486
<dt><code>Dict[int, <a>pdoc.Doc</a>]</code></dt>
14851487
<dd>Description.</dd>
14861488
</dl>
1489+
<h2 id="returns_3">Returns</h2>
1490+
<dl>
1491+
<dt><code>int | str</code></dt>
1492+
<dd>Description.</dd>
1493+
</dl>
14871494
<h2 id="raises">Raises</h2>
14881495
<dl>
14891496
<dt><code>AttributeError</code></dt>

pdoc/test/example_pkg/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def google(self):
223223
Args:
224224
arg1 (int): Description of arg1
225225
arg2 (str or int): Description of arg2
226+
arg3 (str | None): Description of arg3
226227
test_sequence: 2-dim numpy array of real numbers, size: N * D
227228
- the test observation sequence.
228229
@@ -244,6 +245,9 @@ def google(self):
244245
Returns:
245246
Dict[int, pdoc.Doc]: Description.
246247
248+
Returns:
249+
int | str: Description.
250+
247251
Raises:
248252
AttributeError: The ``Raises`` section is a list of all exceptions
249253
that are relevant to the interface.

0 commit comments

Comments
 (0)