gh-104050: Argument clinic: annotate format_docstring() (#107200)

This commit is contained in:
Alex Waygood 2023-07-24 21:29:50 +01:00 committed by GitHub
parent e5d5522612
commit ac2d85a174
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5294,8 +5294,10 @@ def state_function_docstring(self, line):
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 @@ def format_docstring(self):
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 @@ def fix_right_bracket_count(desired):
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 @@ def add_parameter(text):
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 @@ def add_parameter(text):
add(docstring)
docstring = output()
docstring = linear_format(docstring, parameters=parameters)
docstring = linear_format(docstring, parameters=parameters_output)
docstring = docstring.rstrip()
return docstring