Skip to content

gh-104050: Argument Clinic: Annotate Clinic.parse() #106760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
Literal,
NamedTuple,
NoReturn,
Protocol,
TypeGuard,
overload,
)
Expand Down Expand Up @@ -2055,7 +2056,12 @@ def write_file(filename: str, new_contents: str) -> None:
ClassDict = dict[str, "Class"]
DestinationDict = dict[str, Destination]
ModuleDict = dict[str, "Module"]
ParserDict = dict[str, "DSLParser"]


class Parser(Protocol):
def __init__(self, clinic: Clinic) -> None: ...
def parse(self, block: Block) -> None: ...


clinic = None
class Clinic:
Expand Down Expand Up @@ -2113,7 +2119,7 @@ def __init__(
) -> None:
# maps strings to Parser objects.
# (instantiated from the "parsers" global.)
self.parsers: ParserDict = {}
self.parsers: dict[str, Parser] = {}
self.language: CLanguage = language
if printer:
fail("Custom printers are broken right now")
Expand Down Expand Up @@ -2205,7 +2211,7 @@ def get_destination_buffer(
d = self.get_destination(name)
return d.buffers[item]

def parse(self, input):
def parse(self, input: str) -> str:
printer = self.printer
self.block_parser = BlockParser(input, self.language, verify=self.verify)
for block in self.block_parser:
Expand Down Expand Up @@ -5521,7 +5527,10 @@ def state_terminal(self, line):
# "clinic", handles the Clinic DSL
# "python", handles running Python code
#
parsers = {'clinic' : DSLParser, 'python': PythonParser}
parsers: dict[str, Callable[[Clinic], Parser]] = {
'clinic': DSLParser,
'python': PythonParser,
}


clinic = None
Expand Down