Skip to content

Commit

Permalink
gh-104050: Add more type hints to Argument Clinic DSLParser() (#106354)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
erlend-aasland and AlexWaygood committed Jul 3, 2023
1 parent 0da4c88 commit 2e2daac
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright 2012-2013 by Larry Hastings.
# Licensed to the PSF under a contributor agreement.
#
from __future__ import annotations

import abc
import ast
Expand Down Expand Up @@ -2448,7 +2449,7 @@ def __init__(
cls: Class | None = None,
c_basename: str | None = None,
full_name: str | None = None,
return_converter: ReturnConverterType,
return_converter: CReturnConverter,
return_annotation = inspect.Signature.empty,
docstring: str | None = None,
kind: str = CALLABLE,
Expand All @@ -2467,7 +2468,7 @@ def __init__(
self.docstring = docstring or ''
self.kind = kind
self.coexist = coexist
self.self_converter = None
self.self_converter: self_converter | None = None
# 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 +2532,7 @@ class Parameter:
def __init__(
self,
name: str,
kind: str,
kind: inspect._ParameterKind,
*,
default = inspect.Parameter.empty,
function: Function,
Expand Down Expand Up @@ -4539,7 +4540,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 @@ -4556,13 +4557,14 @@ 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)

# are we cloning?
before, equals, existing = line.rpartition('=')
c_basename: str | None
if equals:
full_name, _, c_basename = before.partition(' as ')
full_name = full_name.strip()
Expand Down Expand Up @@ -4665,8 +4667,9 @@ 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 @@ -4740,7 +4743,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

0 comments on commit 2e2daac

Please sign in to comment.