Skip to content
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

gh-104050: Partially annotate Argument Clinic CLanguage class #106437

Merged
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 19 additions & 6 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,14 @@ def __init__(self, filename):
self.cpp = cpp.Monitor(filename)
self.cpp.fail = fail

def parse_line(self, line):
def parse_line(self, line: str) -> None:
self.cpp.writeline(line)

def render(self, clinic, signatures):
def render(
self,
clinic: Clinic | None,
signatures
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
) -> str:
function = None
for o in signatures:
if isinstance(o, Function):
Expand All @@ -747,7 +751,10 @@ def render(self, clinic, signatures):
function = o
return self.render_function(clinic, function)

def docstring_for_c_string(self, f):
def docstring_for_c_string(
self,
f: Function
) -> str:
if re.search(r'[^\x00-\x7F]', f.docstring):
warn("Non-ascii character appear in docstring.")

Expand Down Expand Up @@ -1328,7 +1335,7 @@ def parser_body(prototype, *fields, declarations=''):
return d2

@staticmethod
def group_to_variable_name(group):
def group_to_variable_name(group: int) -> str:
adjective = "left_" if group < 0 else "right_"
return "group_" + adjective + str(abs(group))

Expand Down Expand Up @@ -1424,8 +1431,12 @@ def render_option_group_parsing(self, f, template_dict):
add("}")
template_dict['option_group_parsing'] = format_escape(output())

def render_function(self, clinic, f):
if not f:
def render_function(
self,
clinic: Clinic | None,
f: Function | None
) -> str:
if f is None or clinic is None:
return ""

add, output = text_accumulator()
Expand Down Expand Up @@ -1487,10 +1498,12 @@ def render_function(self, clinic, f):

template_dict = {}

assert isinstance(f.full_name, str)
full_name = f.full_name
template_dict['full_name'] = full_name

if new_or_init:
assert isinstance(f.cls, Class)
name = f.cls.name
else:
name = f.name
Expand Down