[Python-checkins] gh-104050: Argument Clinic: Annotate Clinic.parse() (#106760)
erlend-aasland
webhook-mailer at python.org
Sun Jul 16 20:04:13 EDT 2023
https://github.com/python/cpython/commit/383dcbebcda576e3a3fd18c9246364f67bb65df5
commit: 383dcbebcda576e3a3fd18c9246364f67bb65df5
branch: main
author: Erlend E. Aasland <erlend at python.org>
committer: erlend-aasland <erlend.aasland at protonmail.com>
date: 2023-07-17T00:04:10Z
summary:
gh-104050: Argument Clinic: Annotate Clinic.parse() (#106760)
Co-authored-by: Alex Waygood <Alex.Waygood at Gmail.com>
files:
M Tools/clinic/clinic.py
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 861a6507eae75..9b7069e9b8fcb 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -42,6 +42,7 @@
Literal,
NamedTuple,
NoReturn,
+ Protocol,
TypeGuard,
overload,
)
@@ -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:
@@ -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")
@@ -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:
@@ -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
More information about the Python-checkins
mailing list