Skip to content

Commit b782455

Browse files
aleksslitvinovsaleksslitvinovs-axoniusmhilsautofix-ci[bot]
authored
Add support for keyword args for Google flavor docs (#840)
* Add support for keyword args for Google flavor docs * add changelog entry * [autofix.ci] apply automated fixes --------- Co-authored-by: aleksslitvinovs-axonius <[email protected]> Co-authored-by: Maximilian Hils <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 34c7759 commit b782455

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
([#831](https://github.com/mitmproxy/pdoc/issues/831), @iFreilicht)
1414
- Replace vendored version of `markdown2` with the [official
1515
upstream](https://github.com/trentm/python-markdown2)
16+
- Add support for keyword args for Google flavor docs.
17+
([#840](https://github.com/mitmproxy/pdoc/pull/840), @aleksslitvinovs)
1618

1719
## 2025-06-04: pdoc 15.0.4
1820

pdoc/docstrings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ def google(docstring: str) -> str:
104104
)
105105

106106

107-
GOOGLE_LIST_SECTIONS = ["Args", "Raises", "Attributes"]
107+
GOOGLE_LIST_SECTIONS = ["Args", "Raises", "Attributes", "Keyword Args"]
108108
"""Section headers listed in the official Google docstring style guide."""
109109

110110
GOOGLE_LIST_SECTION_ALIASES = {
111111
"Parameters": "Args",
112112
"Params": "Args",
113113
"Arguments": "Args",
114+
"Raise": "Raises",
115+
"Keyword Arguments": "Keyword Args",
114116
}
115117
"""
116118
Alternative section headers that are not listed in the official Google

test/testdata/flavors_google.html

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ <h2>API Documentation</h2>
131131
<li>
132132
<a class="function" href="#alternative_section_names">alternative_section_names</a>
133133
</li>
134+
<li>
135+
<a class="function" href="#keyword_arguments">keyword_arguments</a>
136+
</li>
134137
</ul>
135138

136139

@@ -648,6 +651,18 @@ <h6 id="todo">Todo:</h6>
648651
</span><span id="L-453"><a href="#L-453"><span class="linenos">453</span></a><span class="sd"> Parameters:</span>
649652
</span><span id="L-454"><a href="#L-454"><span class="linenos">454</span></a><span class="sd"> test: the test string</span>
650653
</span><span id="L-455"><a href="#L-455"><span class="linenos">455</span></a><span class="sd"> &quot;&quot;&quot;</span>
654+
</span><span id="L-456"><a href="#L-456"><span class="linenos">456</span></a>
655+
</span><span id="L-457"><a href="#L-457"><span class="linenos">457</span></a><span class="k">def</span><span class="w"> </span><span class="nf">keyword_arguments</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
656+
</span><span id="L-458"><a href="#L-458"><span class="linenos">458</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
657+
</span><span id="L-459"><a href="#L-459"><span class="linenos">459</span></a><span class="sd"> This an example for a function with keyword arguments documented in the docstring.</span>
658+
</span><span id="L-460"><a href="#L-460"><span class="linenos">460</span></a>
659+
</span><span id="L-461"><a href="#L-461"><span class="linenos">461</span></a><span class="sd"> Args:</span>
660+
</span><span id="L-462"><a href="#L-462"><span class="linenos">462</span></a><span class="sd"> **kwargs: A dictionary containing user info.</span>
661+
</span><span id="L-463"><a href="#L-463"><span class="linenos">463</span></a>
662+
</span><span id="L-464"><a href="#L-464"><span class="linenos">464</span></a><span class="sd"> Keyword Arguments:</span>
663+
</span><span id="L-465"><a href="#L-465"><span class="linenos">465</span></a><span class="sd"> str_arg (str): First string argument.</span>
664+
</span><span id="L-466"><a href="#L-466"><span class="linenos">466</span></a><span class="sd"> int_arg (int): Second integer argument.</span>
665+
</span><span id="L-467"><a href="#L-467"><span class="linenos">467</span></a><span class="sd"> &quot;&quot;&quot;</span>
651666
</span></pre></div>
652667

653668

@@ -1944,6 +1959,49 @@ <h6 id="arguments">Arguments:</h6>
19441959
</div>
19451960

19461961

1962+
</section>
1963+
<section id="keyword_arguments">
1964+
<input id="keyword_arguments-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
1965+
<div class="attr function">
1966+
1967+
<span class="def">def</span>
1968+
<span class="name">keyword_arguments</span><span class="signature pdoc-code condensed">(<span class="param"><span class="o">**</span><span class="n">kwargs</span></span><span class="return-annotation">):</span></span>
1969+
1970+
<label class="view-source-button" for="keyword_arguments-view-source"><span>View Source</span></label>
1971+
1972+
</div>
1973+
<a class="headerlink" href="#keyword_arguments"></a>
1974+
<div class="pdoc-code codehilite"><pre><span></span><span id="keyword_arguments-458"><a href="#keyword_arguments-458"><span class="linenos">458</span></a><span class="k">def</span><span class="w"> </span><span class="nf">keyword_arguments</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
1975+
</span><span id="keyword_arguments-459"><a href="#keyword_arguments-459"><span class="linenos">459</span></a><span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
1976+
</span><span id="keyword_arguments-460"><a href="#keyword_arguments-460"><span class="linenos">460</span></a><span class="sd"> This an example for a function with keyword arguments documented in the docstring.</span>
1977+
</span><span id="keyword_arguments-461"><a href="#keyword_arguments-461"><span class="linenos">461</span></a>
1978+
</span><span id="keyword_arguments-462"><a href="#keyword_arguments-462"><span class="linenos">462</span></a><span class="sd"> Args:</span>
1979+
</span><span id="keyword_arguments-463"><a href="#keyword_arguments-463"><span class="linenos">463</span></a><span class="sd"> **kwargs: A dictionary containing user info.</span>
1980+
</span><span id="keyword_arguments-464"><a href="#keyword_arguments-464"><span class="linenos">464</span></a>
1981+
</span><span id="keyword_arguments-465"><a href="#keyword_arguments-465"><span class="linenos">465</span></a><span class="sd"> Keyword Arguments:</span>
1982+
</span><span id="keyword_arguments-466"><a href="#keyword_arguments-466"><span class="linenos">466</span></a><span class="sd"> str_arg (str): First string argument.</span>
1983+
</span><span id="keyword_arguments-467"><a href="#keyword_arguments-467"><span class="linenos">467</span></a><span class="sd"> int_arg (int): Second integer argument.</span>
1984+
</span><span id="keyword_arguments-468"><a href="#keyword_arguments-468"><span class="linenos">468</span></a><span class="sd"> &quot;&quot;&quot;</span>
1985+
</span></pre></div>
1986+
1987+
1988+
<div class="docstring"><p>This an example for a function with keyword arguments documented in the docstring.</p>
1989+
1990+
<h6 id="arguments">Arguments:</h6>
1991+
1992+
<ul>
1993+
<li><strong>**kwargs:</strong> A dictionary containing user info.</li>
1994+
</ul>
1995+
1996+
<h6 id="keyword-args">Keyword Args:</h6>
1997+
1998+
<ul>
1999+
<li><strong>str_arg (str):</strong> First string argument.</li>
2000+
<li><strong>int_arg (int):</strong> Second integer argument.</li>
2001+
</ul>
2002+
</div>
2003+
2004+
19472005
</section>
19482006
</main>
19492007
</body>

test/testdata/flavors_google.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,15 @@ def alternative_section_names(test: str):
453453
Parameters:
454454
test: the test string
455455
"""
456+
457+
def keyword_arguments(**kwargs):
458+
"""
459+
This an example for a function with keyword arguments documented in the docstring.
460+
461+
Args:
462+
**kwargs: A dictionary containing user info.
463+
464+
Keyword Arguments:
465+
str_arg (str): First string argument.
466+
int_arg (int): Second integer argument.
467+
"""

test/testdata/flavors_google.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@
4444
<function def example_code(): ... # Test case for https:…>
4545
<function def newline_after_args(test: str): ... # Test case for https:…>
4646
<function def alternative_section_names(test: str): ... # In this example, we …>
47+
<function def keyword_arguments(**kwargs): ... # This an example for …>
4748
>

0 commit comments

Comments
 (0)