Skip to content

Commit d93fe5a

Browse files
authored
gh-104050: Argument clinic: misc improvements to type annotation coverage (#107206)
1 parent 7608fa8 commit d93fe5a

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Tools/clinic/clinic.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ class LandMine:
26402640
# try to access any
26412641
__message__: str
26422642

2643-
def __getattribute__(self, name: str):
2643+
def __getattribute__(self, name: str) -> Any:
26442644
if name in ('__repr__', '__message__'):
26452645
return super().__getattribute__(name)
26462646
# raise RuntimeError(repr(name))
@@ -3896,7 +3896,7 @@ def converter_init(self, *, accept: TypeSet = {buffer}) -> None:
38963896

38973897
self.format_unit = format_unit
38983898

3899-
def cleanup(self):
3899+
def cleanup(self) -> str:
39003900
name = self.name
39013901
return "".join(["if (", name, ".obj) {\n PyBuffer_Release(&", name, ");\n}\n"])
39023902

@@ -4115,7 +4115,7 @@ def __init__(
41154115
self,
41164116
*,
41174117
py_default: str | None = None,
4118-
**kwargs
4118+
**kwargs: Any
41194119
) -> None:
41204120
self.py_default = py_default
41214121
try:
@@ -4493,7 +4493,7 @@ def directive_destination(
44934493
self,
44944494
name: str,
44954495
command: str,
4496-
*args
4496+
*args: str
44974497
) -> None:
44984498
match command:
44994499
case "new":
@@ -4847,12 +4847,13 @@ def state_parameters_start(self, line: str | None) -> None:
48474847
return self.next(self.state_parameter, line)
48484848

48494849

4850-
def to_required(self):
4850+
def to_required(self) -> None:
48514851
"""
48524852
Transition to the "required" parameter state.
48534853
"""
48544854
if self.parameter_state is not ParamState.REQUIRED:
48554855
self.parameter_state = ParamState.REQUIRED
4856+
assert self.function is not None
48564857
for p in self.function.parameters.values():
48574858
p.group = -p.group
48584859

@@ -5000,7 +5001,7 @@ def parse_parameter(self, line: str) -> None:
50005001
# of disallowed ast nodes.
50015002
class DetectBadNodes(ast.NodeVisitor):
50025003
bad = False
5003-
def bad_node(self, node):
5004+
def bad_node(self, node: ast.AST) -> None:
50045005
self.bad = True
50055006

50065007
# inline function call
@@ -5248,7 +5249,9 @@ def state_parameter_docstring_start(self, line: str | None) -> None:
52485249
# every line of the docstring must start with at least F spaces,
52495250
# where F > P.
52505251
# these F spaces will be stripped.
5251-
def state_parameter_docstring(self, line):
5252+
def state_parameter_docstring(self, line: str | None) -> None:
5253+
assert line is not None
5254+
52525255
stripped = line.strip()
52535256
if stripped.startswith('#'):
52545257
return
@@ -5263,7 +5266,7 @@ def state_parameter_docstring(self, line):
52635266
assert self.indent.depth == 1
52645267
return self.next(self.state_function_docstring, line)
52655268

5266-
assert self.function.parameters
5269+
assert self.function and self.function.parameters
52675270
last_parameter = next(reversed(list(self.function.parameters.values())))
52685271

52695272
new_docstring = last_parameter.docstring
@@ -5276,7 +5279,10 @@ def state_parameter_docstring(self, line):
52765279
last_parameter.docstring = new_docstring
52775280

52785281
# the final stanza of the DSL is the docstring.
5279-
def state_function_docstring(self, line):
5282+
def state_function_docstring(self, line: str | None) -> None:
5283+
assert self.function is not None
5284+
assert line is not None
5285+
52805286
if self.group:
52815287
fail("Function " + self.function.name + " has a ] without a matching [.")
52825288

0 commit comments

Comments
 (0)