diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-07-11 21:21:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-11 21:21:14 (GMT) |
commit | d0972c77aa1cd5fe27618e82c10141a2bf157476 (patch) | |
tree | f5e602602fd7248adf012ab688800af0267fe524 /Tools/clinic | |
parent | 3590c45a3d564b3182ae21d899bae81c49d685a2 (diff) | |
download | cpython-d0972c77aa1cd5fe27618e82c10141a2bf157476.zip cpython-d0972c77aa1cd5fe27618e82c10141a2bf157476.tar.gz cpython-d0972c77aa1cd5fe27618e82c10141a2bf157476.tar.bz2 |
gh-104050: Argument Clinic: Annotate the `Block` class (#106519)
Diffstat (limited to 'Tools/clinic')
-rwxr-xr-x | Tools/clinic/clinic.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 19c5f57..12ab633 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -759,7 +759,7 @@ class CLanguage(Language): def render( self, clinic: Clinic | None, - signatures: Iterable[Function] + signatures: Iterable[Module | Class | Function] ) -> str: function = None for o in signatures: @@ -1633,6 +1633,7 @@ def create_regex( return re.compile(pattern) +@dc.dataclass(slots=True, repr=False) class Block: r""" Represents a single block of text embedded in @@ -1679,18 +1680,16 @@ class Block: "preindent" would be "____" and "indent" would be "__". """ - def __init__(self, input, dsl_name=None, signatures=None, output=None, indent='', preindent=''): - assert isinstance(input, str) - self.input = input - self.dsl_name = dsl_name - self.signatures = signatures or [] - self.output = output - self.indent = indent - self.preindent = preindent + input: str + dsl_name: str | None = None + signatures: list[Module | Class | Function] = dc.field(default_factory=list) + output: Any = None # TODO: Very dynamic; probably untypeable in its current form? + indent: str = '' + preindent: str = '' - def __repr__(self): + def __repr__(self) -> str: dsl_name = self.dsl_name or "text" - def summarize(s): + def summarize(s: object) -> str: s = repr(s) if len(s) > 30: return s[:26] + "..." + s[0] @@ -4619,10 +4618,13 @@ class DSLParser: if not (existing_function.kind == self.kind and existing_function.coexist == self.coexist): fail("'kind' of function and cloned function don't match! (@classmethod/@staticmethod/@coexist)") - self.function = existing_function.copy(name=function_name, full_name=full_name, module=module, cls=cls, c_basename=c_basename, docstring='') - - self.block.signatures.append(self.function) - (cls or module).functions.append(self.function) + function = existing_function.copy( + name=function_name, full_name=full_name, module=module, + cls=cls, c_basename=c_basename, docstring='' + ) + self.function = function + self.block.signatures.append(function) + (cls or module).functions.append(function) self.next(self.state_function_docstring) return |