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 3 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
13 changes: 7 additions & 6 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
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 @@ -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 All @@ -5031,6 +5031,7 @@ def parse_converter(annotation: ast.expr | None) -> tuple[str, bool, KwargDict]:
case ast.Name(name):
return name, False, {}
case ast.Call(func=ast.Name(name)):
assert isinstance(ast.expr, str)
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
symbols = globals()
kwargs = {
node.arg: eval_ast_expr(node.value, symbols)
Expand Down