Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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