From 836690e15051d613172d8ba37008f12092e8fe69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oleg=20H=C3=B6fling?= Date: Mon, 2 Aug 2021 14:04:42 +0200 Subject: [PATCH] Add attribute types to `code.InteractiveInterpreter` and `code.InteractiveConsole` (#5830) * mark undocumented attributes * use pep 585 generics, replace optional types with pep 604-style hints --- stdlib/code.pyi | 25 +++++++++++++++---------- stdlib/linecache.pyi | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/stdlib/code.pyi b/stdlib/code.pyi index 5111e928e..ed00eaf96 100644 --- a/stdlib/code.pyi +++ b/stdlib/code.pyi @@ -1,25 +1,30 @@ +from codeop import CommandCompiler from types import CodeType -from typing import Any, Callable, Mapping, Optional +from typing import Any, Callable, Mapping class InteractiveInterpreter: - def __init__(self, locals: Optional[Mapping[str, Any]] = ...) -> None: ... + locals: Mapping[str, Any] # undocumented + compile: CommandCompiler # undocumented + def __init__(self, locals: Mapping[str, Any] | None = ...) -> None: ... def runsource(self, source: str, filename: str = ..., symbol: str = ...) -> bool: ... def runcode(self, code: CodeType) -> None: ... - def showsyntaxerror(self, filename: Optional[str] = ...) -> None: ... + def showsyntaxerror(self, filename: str | None = ...) -> None: ... def showtraceback(self) -> None: ... def write(self, data: str) -> None: ... class InteractiveConsole(InteractiveInterpreter): - def __init__(self, locals: Optional[Mapping[str, Any]] = ..., filename: str = ...) -> None: ... - def interact(self, banner: Optional[str] = ..., exitmsg: Optional[str] = ...) -> None: ... + buffer: list[str] # undocumented + filename: str # undocumented + def __init__(self, locals: Mapping[str, Any] | None = ..., filename: str = ...) -> None: ... + def interact(self, banner: str | None = ..., exitmsg: str | None = ...) -> None: ... def push(self, line: str) -> bool: ... def resetbuffer(self) -> None: ... def raw_input(self, prompt: str = ...) -> str: ... def interact( - banner: Optional[str] = ..., - readfunc: Optional[Callable[[str], str]] = ..., - local: Optional[Mapping[str, Any]] = ..., - exitmsg: Optional[str] = ..., + banner: str | None = ..., + readfunc: Callable[[str], str] | None = ..., + local: Mapping[str, Any] | None = ..., + exitmsg: str | None = ..., ) -> None: ... -def compile_command(source: str, filename: str = ..., symbol: str = ...) -> Optional[CodeType]: ... +def compile_command(source: str, filename: str = ..., symbol: str = ...) -> CodeType | None: ... diff --git a/stdlib/linecache.pyi b/stdlib/linecache.pyi index 39b9a25b8..1415bafdf 100644 --- a/stdlib/linecache.pyi +++ b/stdlib/linecache.pyi @@ -6,7 +6,7 @@ _ModuleMetadata = Tuple[int, float, List[str], str] class _SourceLoader(Protocol): def __call__(self) -> str | None: ... -cache: Dict[str, _SourceLoader | _ModuleMetadata] +cache: Dict[str, _SourceLoader | _ModuleMetadata] # undocumented def getline(filename: str, lineno: int, module_globals: _ModuleGlobals | None = ...) -> str: ... def clearcache() -> None: ...