FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-104050: Argument Clinic: Annotate the `Block` class by AlexWaygood · Pull Request #106519 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
32 changes: 17 additions & 15 deletions Tools/clinic/clinic.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def parse_line(self, line: str) -> None:
def render(
self,
clinic: Clinic | None,
signatures: Iterable[Function]
signatures: Iterable[Module | Class | Function]
) -> str:
function = None
for o in signatures:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -4619,10 +4618,13 @@ def state_modulename_name(self, line: str | None) -> None:

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

Expand Down

Back | FazBrowse Home | New Git URL