|
42 | 42 | Literal,
|
43 | 43 | NamedTuple,
|
44 | 44 | NoReturn,
|
| 45 | + Protocol, |
45 | 46 | TypeGuard,
|
46 | 47 | overload,
|
47 | 48 | )
|
@@ -2055,7 +2056,12 @@ def write_file(filename: str, new_contents: str) -> None:
|
2055 | 2056 | ClassDict = dict[str, "Class"]
|
2056 | 2057 | DestinationDict = dict[str, Destination]
|
2057 | 2058 | ModuleDict = dict[str, "Module"]
|
2058 |
| -ParserDict = dict[str, "DSLParser"] |
| 2059 | + |
| 2060 | + |
| 2061 | +class Parser(Protocol): |
| 2062 | + def __init__(self, clinic: Clinic) -> None: ... |
| 2063 | + def parse(self, block: Block) -> None: ... |
| 2064 | + |
2059 | 2065 |
|
2060 | 2066 | clinic = None
|
2061 | 2067 | class Clinic:
|
@@ -2113,7 +2119,7 @@ def __init__(
|
2113 | 2119 | ) -> None:
|
2114 | 2120 | # maps strings to Parser objects.
|
2115 | 2121 | # (instantiated from the "parsers" global.)
|
2116 |
| - self.parsers: ParserDict = {} |
| 2122 | + self.parsers: dict[str, Parser] = {} |
2117 | 2123 | self.language: CLanguage = language
|
2118 | 2124 | if printer:
|
2119 | 2125 | fail("Custom printers are broken right now")
|
@@ -2205,7 +2211,7 @@ def get_destination_buffer(
|
2205 | 2211 | d = self.get_destination(name)
|
2206 | 2212 | return d.buffers[item]
|
2207 | 2213 |
|
2208 |
| - def parse(self, input): |
| 2214 | + def parse(self, input: str) -> str: |
2209 | 2215 | printer = self.printer
|
2210 | 2216 | self.block_parser = BlockParser(input, self.language, verify=self.verify)
|
2211 | 2217 | for block in self.block_parser:
|
@@ -5521,7 +5527,10 @@ def state_terminal(self, line):
|
5521 | 5527 | # "clinic", handles the Clinic DSL
|
5522 | 5528 | # "python", handles running Python code
|
5523 | 5529 | #
|
5524 |
| -parsers = {'clinic' : DSLParser, 'python': PythonParser} |
| 5530 | +parsers: dict[str, Callable[[Clinic], Parser]] = { |
| 5531 | + 'clinic': DSLParser, |
| 5532 | + 'python': PythonParser, |
| 5533 | +} |
5525 | 5534 |
|
5526 | 5535 |
|
5527 | 5536 | clinic = None
|
|
0 commit comments