Skip to content

Commit d0972c7

Browse files
authored
gh-104050: Argument Clinic: Annotate the Block class (#106519)
1 parent 3590c45 commit d0972c7

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

Tools/clinic/clinic.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def parse_line(self, line: str) -> None:
759759
def render(
760760
self,
761761
clinic: Clinic | None,
762-
signatures: Iterable[Function]
762+
signatures: Iterable[Module | Class | Function]
763763
) -> str:
764764
function = None
765765
for o in signatures:
@@ -1633,6 +1633,7 @@ def create_regex(
16331633
return re.compile(pattern)
16341634

16351635

1636+
@dc.dataclass(slots=True, repr=False)
16361637
class Block:
16371638
r"""
16381639
Represents a single block of text embedded in
@@ -1679,18 +1680,16 @@ class Block:
16791680
"preindent" would be "____" and "indent" would be "__".
16801681
16811682
"""
1682-
def __init__(self, input, dsl_name=None, signatures=None, output=None, indent='', preindent=''):
1683-
assert isinstance(input, str)
1684-
self.input = input
1685-
self.dsl_name = dsl_name
1686-
self.signatures = signatures or []
1687-
self.output = output
1688-
self.indent = indent
1689-
self.preindent = preindent
1683+
input: str
1684+
dsl_name: str | None = None
1685+
signatures: list[Module | Class | Function] = dc.field(default_factory=list)
1686+
output: Any = None # TODO: Very dynamic; probably untypeable in its current form?
1687+
indent: str = ''
1688+
preindent: str = ''
16901689

1691-
def __repr__(self):
1690+
def __repr__(self) -> str:
16921691
dsl_name = self.dsl_name or "text"
1693-
def summarize(s):
1692+
def summarize(s: object) -> str:
16941693
s = repr(s)
16951694
if len(s) > 30:
16961695
return s[:26] + "..." + s[0]
@@ -4619,10 +4618,13 @@ def state_modulename_name(self, line: str | None) -> None:
46194618

46204619
if not (existing_function.kind == self.kind and existing_function.coexist == self.coexist):
46214620
fail("'kind' of function and cloned function don't match! (@classmethod/@staticmethod/@coexist)")
4622-
self.function = existing_function.copy(name=function_name, full_name=full_name, module=module, cls=cls, c_basename=c_basename, docstring='')
4623-
4624-
self.block.signatures.append(self.function)
4625-
(cls or module).functions.append(self.function)
4621+
function = existing_function.copy(
4622+
name=function_name, full_name=full_name, module=module,
4623+
cls=cls, c_basename=c_basename, docstring=''
4624+
)
4625+
self.function = function
4626+
self.block.signatures.append(function)
4627+
(cls or module).functions.append(function)
46264628
self.next(self.state_function_docstring)
46274629
return
46284630

0 commit comments

Comments
 (0)