10000 gh-104050: Argument Clinic: Annotate Clinic.parse() by erlend-aasland · Pull Request #106760 · python/cpython · GitHub
[go: up one dir, main page]

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 1 commit
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
Prev Previous commit
Next Next commit
Make it protocol!
  • Loading branch information
erlend-aasland committed Jul 15, 2023
commit edcd854be4af147812cd5ace947f9ba490742c40
24 changes: 14 additions & 10 deletions Tools/clinic/clinic.py
C964
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 @@ -2052,16 +2053,19 @@ def write_file(filename: str, new_contents: str) -> None:
raise


class Parser:
ClassDict = dict[str, "Class"]
DestinationDict = dict[str, Destination]
ModuleDict = dict[str, "Module"]


class Parser(Protocol):

@abc.abstractmethod
def parse(self, block: Block) -> None: ...
def __init__(self, *args, **kwargs): ...

@abc.abstractmethod
def parse(self, block: Block) -> None: ...

ClassDict = dict[str, "Class"]
DestinationDict = dict[str, Destination]
ModuleDict = dict[str, "Module"]
ParserDict = dict[str, Parser]

clinic = None
class Clinic:
Expand Down Expand Up @@ -2119,7 +2123,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 @@ -2347,7 +2351,7 @@ def compute_checksum(
return s


class PythonParser(Parser):
class PythonParser:
def __init__(self, clinic: Clinic) -> None:
pass

Expand Down Expand Up @@ -4367,7 +4371,7 @@ class ParamState(enum.IntEnum):
RIGHT_SQUARE_AFTER = 6


class DSLParser(Parser):
class DSLParser:
function: Function | None
state: StateKeeper
keyword_only: bool
Expand Down Expand Up @@ -5527,7 +5531,7 @@ def state_terminal(self, line):
# "clinic", handles the Clinic DSL
# "python", handles running Python code
#
parsers = {'clinic' : DSLParser, 'python': PythonParser}
parsers: dict[str, type[Parser]] = {'clinic' : DSLParser, 'python': PythonParser}


clinic = None
Expand Down
0