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: Add more type hints to Argument Clinic DSLParser() #106354

Merged
merged 19 commits into from
Jul 3, 2023
Merged
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
24 changes: 12 additions & 12 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2467,7 +2467,7 @@ def __init__(
self.docstring = docstring or ''
self.kind = kind
self.coexist = coexist
self.self_converter = None
self.self_converter: CConverter | None = None
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
# docstring_only means "don't generate a machine-readable
# signature, just a normal docstring". it's True for
# functions with optional groups because we can't represent
Expand Down Expand Up @@ -2531,7 +2531,7 @@ class Parameter:
def __init__(
self,
name: str,
kind: str,
kind: inspect._ParameterKind,
*,
default = inspect.Parameter.empty,
function: Function,
Expand Down Expand Up @@ -4311,7 +4311,7 @@ def __init__(self, clinic: Clinic) -> None:
self.reset()

def reset(self) -> None:
self.function = None
self.function: Function | None = None
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
self.state: StateKeeper = self.state_dsl_start
self.parameter_indent = None
self.keyword_only = False
Expand Down Expand Up @@ -4526,7 +4526,7 @@ def state_dsl_start(self, line: str | None) -> None:

self.next(self.state_modulename_name, line)

def state_modulename_name(self, line):
def state_modulename_name(self, line: str | None) -> None:
# looking for declaration, which establishes the leftmost column
# line should be
# modulename.fnname [as c_basename] [-> return annotation]
Expand All @@ -4543,7 +4543,7 @@ def state_modulename_name(self, line):
# this line is permitted to start with whitespace.
# we'll call this number of spaces F (for "function").

if not line.strip():
if not self.valid_line(line):
return

self.indent.infer(line)
Expand Down Expand Up @@ -4588,9 +4588,9 @@ def state_modulename_name(self, line):

line, _, returns = line.partition('->')

full_name, _, c_basename = line.partition(' as ')
full_name = full_name.strip()
c_basename = c_basename.strip() or None
left, _, right = line.partition(' as ')
full_name = left.strip()
c_basename = right.strip() or None
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved

if not is_legal_py_identifier(full_name):
fail("Illegal function name:", full_name)
Expand Down Expand Up @@ -4652,8 +4652,8 @@ def state_modulename_name(self, line):
if cls and type == "PyObject *":
kwargs['type'] = cls.typedef
sc = self.function.self_converter = self_converter(name, name, self.function, **kwargs)
p_self = Parameter(sc.name, inspect.Parameter.POSITIONAL_ONLY, function=self.function, converter=sc)
self.function.parameters[sc.name] = p_self
p_self = Parameter(name, inspect.Parameter.POSITIONAL_ONLY, function=self.function, converter=sc)
self.function.parameters[name] = p_self

(cls or module).functions.append(self.function)
self.next(self.state_parameters_start)
Expand Down Expand Up @@ -4727,7 +4727,7 @@ def state_modulename_name(self, line):
ps_start, ps_left_square_before, ps_group_before, ps_required, \
ps_optional, ps_group_after, ps_right_square_after = range(7)

def state_parameters_start(self, line: str) -> None:
def state_parameters_start(self, line: str | None) -> None:
if not self.valid_line(line):
return

Expand Down Expand Up @@ -5021,7 +5021,7 @@ def bad_node(self, node):
key = f"{parameter_name}_as_{c_name}" if c_name else parameter_name
self.function.parameters[key] = p

KwargDict = dict[str | None, Any]
KwargDict = dict[str, Any]

@staticmethod
def parse_converter(annotation: ast.expr | None) -> tuple[str, bool, KwargDict]:
Expand Down