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

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Erlend E. Aasland 2023-07-17 02:04:10 +02:00 committed by GitHub
parent c41320701b
commit 383dcbebcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,6 +42,7 @@ from typing import (
Literal, Literal,
NamedTuple, NamedTuple,
NoReturn, NoReturn,
Protocol,
TypeGuard, TypeGuard,
overload, overload,
) )
@ -2055,7 +2056,12 @@ def write_file(filename: str, new_contents: str) -> None:
ClassDict = dict[str, "Class"] ClassDict = dict[str, "Class"]
DestinationDict = dict[str, Destination] DestinationDict = dict[str, Destination]
ModuleDict = dict[str, "Module"] 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 clinic = None
class Clinic: class Clinic:
@ -2113,7 +2119,7 @@ impl_definition block
) -> None: ) -> None:
# maps strings to Parser objects. # maps strings to Parser objects.
# (instantiated from the "parsers" global.) # (instantiated from the "parsers" global.)
self.parsers: ParserDict = {} self.parsers: dict[str, Parser] = {}
self.language: CLanguage = language self.language: CLanguage = language
if printer: if printer:
fail("Custom printers are broken right now") fail("Custom printers are broken right now")
@ -2205,7 +2211,7 @@ impl_definition block
d = self.get_destination(name) d = self.get_destination(name)
return d.buffers[item] return d.buffers[item]
def parse(self, input): def parse(self, input: str) -> str:
printer = self.printer printer = self.printer
self.block_parser = BlockParser(input, self.language, verify=self.verify) self.block_parser = BlockParser(input, self.language, verify=self.verify)
for block in self.block_parser: for block in self.block_parser:
@ -5521,7 +5527,10 @@ class DSLParser:
# "clinic", handles the Clinic DSL # "clinic", handles the Clinic DSL
# "python", handles running Python code # "python", handles running Python code
# #
parsers = {'clinic' : DSLParser, 'python': PythonParser} parsers: dict[str, Callable[[Clinic], Parser]] = {
'clinic': DSLParser,
'python': PythonParser,
}
clinic = None clinic = None