From a6a744a9d099d0a956ea073fa1d11a961a5d7092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oleg=20H=C3=B6fling?= Date: Sat, 24 Jul 2021 14:59:33 +0200 Subject: [PATCH] Add type hint for `linecache.cache` dict (#5805) --- stdlib/linecache.pyi | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/stdlib/linecache.pyi b/stdlib/linecache.pyi index 73c773876..39b9a25b8 100644 --- a/stdlib/linecache.pyi +++ b/stdlib/linecache.pyi @@ -1,10 +1,16 @@ -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Protocol, Tuple _ModuleGlobals = Dict[str, Any] +_ModuleMetadata = Tuple[int, float, List[str], str] -def getline(filename: str, lineno: int, module_globals: Optional[_ModuleGlobals] = ...) -> str: ... +class _SourceLoader(Protocol): + def __call__(self) -> str | None: ... + +cache: Dict[str, _SourceLoader | _ModuleMetadata] + +def getline(filename: str, lineno: int, module_globals: _ModuleGlobals | None = ...) -> str: ... def clearcache() -> None: ... -def getlines(filename: str, module_globals: Optional[_ModuleGlobals] = ...) -> List[str]: ... -def checkcache(filename: Optional[str] = ...) -> None: ... -def updatecache(filename: str, module_globals: Optional[_ModuleGlobals] = ...) -> List[str]: ... +def getlines(filename: str, module_globals: _ModuleGlobals | None = ...) -> List[str]: ... +def checkcache(filename: str | None = ...) -> None: ... +def updatecache(filename: str, module_globals: _ModuleGlobals | None = ...) -> List[str]: ... def lazycache(filename: str, module_globals: _ModuleGlobals) -> bool: ...