Skip to content

Commit

Permalink
ENH: Handle union type expressions for Google style docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo committed Jun 22, 2024
1 parent 84ee28b commit 7686f66
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pdoc/html_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ def googledoc_sections(match):
section = section.title()
if section in ('Args', 'Attributes'):
body = re.compile(
r'^([\w*]+)(?: \(([\w.,=\[\] -]+)\))?: '
r'^([\w*]+)(?: \(([\w.,=|\[\] -]+)\))?: '
r'((?:.*)(?:\n(?: {2,}.*|$))*)', re.MULTILINE).sub(
lambda m: _ToMarkdown._deflist(*_ToMarkdown._fix_indent(*m.groups())),
inspect.cleandoc(f'\n{body}')
)
elif section in ('Returns', 'Yields', 'Raises', 'Warns'):
body = re.compile(
r'^()([\w.,\[\] ]+): '
r'^()([\w.,|\[\] ]+): '
r'((?:.*)(?:\n(?: {2,}.*|$))*)', re.MULTILINE).sub(
lambda m: _ToMarkdown._deflist(*_ToMarkdown._fix_indent(*m.groups())),
inspect.cleandoc(f'\n{body}')
Expand Down
7 changes: 7 additions & 0 deletions pdoc/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,8 @@ def test_google(self):
<dd>Description of arg1</dd>
<dt><strong><code>arg2</code></strong> :&ensp;<code>str</code> or <code>int</code></dt>
<dd>Description of arg2</dd>
<dt><strong><code>arg3</code></strong> :&ensp;<code>str | None</code></dt>
<dd>Description of arg3</dd>
<dt><strong><code>test_sequence</code></strong></dt>
<dd>
<p>2-dim numpy array of real numbers, size: N * D
Expand Down Expand Up @@ -1484,6 +1486,11 @@ def test_google(self):
<dt><code>Dict[int, <a>pdoc.Doc</a>]</code></dt>
<dd>Description.</dd>
</dl>
<h2 id="returns_3">Returns</h2>
<dl>
<dt><code>int | str</code></dt>
<dd>Description.</dd>
</dl>
<h2 id="raises">Raises</h2>
<dl>
<dt><code>AttributeError</code></dt>
Expand Down
4 changes: 4 additions & 0 deletions pdoc/test/example_pkg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def google(self):
Args:
arg1 (int): Description of arg1
arg2 (str or int): Description of arg2
arg3 (str | None): Description of arg3
test_sequence: 2-dim numpy array of real numbers, size: N * D
- the test observation sequence.
Expand All @@ -243,6 +244,9 @@ def google(self):
Returns:
Dict[int, pdoc.Doc]: Description.
Returns:
int | str: Description.
Raises:
AttributeError: The ``Raises`` section is a list of all exceptions
Expand Down

0 comments on commit 7686f66

Please sign in to comment.