summaryrefslogtreecommitdiffstats
path: root/Tools/clinic
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2023-08-09 12:44:26 (GMT)
committerGitHub <noreply@github.com>2023-08-09 12:44:26 (GMT)
commit1b3f5f24af95c0476ba339ed786a8a4a2578362a (patch)
treee52cc49a1b3dab60e50cd80cafaedeed38aad8f7 /Tools/clinic
parent65ce3652fa47a34acf715ee07bf0a2fae2e0da51 (diff)
downloadcpython-1b3f5f24af95c0476ba339ed786a8a4a2578362a.zip
cpython-1b3f5f24af95c0476ba339ed786a8a4a2578362a.tar.gz
cpython-1b3f5f24af95c0476ba339ed786a8a4a2578362a.tar.bz2
gh-104683: Argument Clinic: Params now render their own docstrings (#107790)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Tools/clinic')
-rwxr-xr-xTools/clinic/clinic.py27
1 files changed, 11 insertions, 16 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 059c2db..3490d48 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -2775,6 +2775,13 @@ class Parameter:
else:
return f'"argument {i}"'
+ def render_docstring(self) -> str:
+ add, out = text_accumulator()
+ add(f" {self.name}\n")
+ for line in self.docstring.split("\n"):
+ add(f" {line}\n")
+ return out().rstrip()
+
CConverterClassT = TypeVar("CConverterClassT", bound=type["CConverter"])
@@ -5686,23 +5693,11 @@ class DSLParser:
@staticmethod
def format_docstring_parameters(params: list[Parameter]) -> str:
"""Create substitution text for {parameters}"""
- text, add, output = _text_accumulator()
- spacer_line = False
- for param in params:
- docstring = param.docstring.strip()
- if not docstring:
- continue
- if spacer_line:
+ add, output = text_accumulator()
+ for p in params:
+ if p.docstring:
+ add(p.render_docstring())
add('\n')
- else:
- spacer_line = True
- add(" ")
- add(param.name)
- add('\n')
- stripped = rstrip_lines(docstring)
- add(textwrap.indent(stripped, " "))
- if text:
- add('\n')
return output()
def format_docstring(self) -> str: