Skip to content

Commit

Permalink
pythongh-104050: Argument clinic: annotate format_docstring() (pyth…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored and jtcave committed Jul 27, 2023
1 parent b8564f6 commit dbf6f44
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dbf6f44

Please sign in to comment.