]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-104050: Argument clinic: annotate `format_docstring()` (#107200)
authorAlex Waygood <Alex.Waygood@Gmail.com>
Mon, 24 Jul 2023 20:29:50 +0000 (21:29 +0100)
committerGitHub <noreply@github.com>
Mon, 24 Jul 2023 20:29:50 +0000 (20:29 +0000)
Tools/clinic/clinic.py

index c9c57f1fdbb3b358a59e771fd2b575b70d6bdde7..59e0bf684d32e2d8bd122e1f431c95cd0970f7be 100755 (executable)
@@ -5294,8 +5294,10 @@ class DSLParser:
         new_docstring += line
         self.function.docstring = new_docstring
 
-    def format_docstring(self):
+    def format_docstring(self) -> str:
         f = self.function
+        assert f is not None
+        assert f.full_name is not None
 
         new_or_init = f.kind.new_or_init
         if new_or_init and not f.docstring:
@@ -5338,7 +5340,7 @@ class DSLParser:
 
         right_bracket_count = 0
 
-        def fix_right_bracket_count(desired):
+        def fix_right_bracket_count(desired: int) -> str:
             nonlocal right_bracket_count
             s = ''
             while right_bracket_count < desired:
@@ -5372,7 +5374,7 @@ class DSLParser:
         last_p = parameters[-1]
         line_length = len(''.join(text))
         indent = " " * line_length
-        def add_parameter(text):
+        def add_parameter(text: str) -> None:
             nonlocal line_length
             nonlocal first_parameter
             if first_parameter:
@@ -5488,9 +5490,9 @@ class DSLParser:
             add(p.name)
             add('\n')
             add(textwrap.indent(rstrip_lines(p.docstring.rstrip()), "    "))
-        parameters = output()
-        if parameters:
-            parameters += '\n'
+        parameters_output = output()
+        if parameters_output:
+            parameters_output += '\n'
 
         ##
         ## docstring body
@@ -5538,7 +5540,7 @@ class DSLParser:
         add(docstring)
         docstring = output()
 
-        docstring = linear_format(docstring, parameters=parameters)
+        docstring = linear_format(docstring, parameters=parameters_output)
         docstring = docstring.rstrip()
 
         return docstring