Skip to content

Commit a906d54

Browse files
authored
Improve pydoc typings (#7152)
Enforce same type HTMLDoc.multicolumn "list" and "format" arguments. Annotate ModuleScanner.run "key" argument.
1 parent 96a09f6 commit a906d54

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

stdlib/pydoc.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from _typeshed import SupportsWrite
22
from reprlib import Repr
33
from types import MethodType, ModuleType, TracebackType
4-
from typing import IO, Any, AnyStr, Callable, Container, Mapping, MutableMapping, NoReturn, Optional
4+
from typing import IO, Any, AnyStr, Callable, Container, Mapping, MutableMapping, NoReturn, TypeVar
55

66
# the return type of sys.exc_info(), used by ErrorDuringImport.__init__
7-
_Exc_Info = tuple[Optional[type[BaseException]], Optional[BaseException], Optional[TracebackType]]
7+
_Exc_Info = tuple[type[BaseException] | None, BaseException | None, TracebackType | None]
8+
9+
_T = TypeVar("_T")
810

911
__author__: str
1012
__date__: str
@@ -81,7 +83,7 @@ class HTMLDoc(Doc):
8183
) -> str: ...
8284
def bigsection(self, title: str, *args: Any) -> str: ...
8385
def preformat(self, text: str) -> str: ...
84-
def multicolumn(self, list: list[Any], format: Callable[[Any], str], cols: int = ...) -> str: ...
86+
def multicolumn(self, list: list[_T], format: Callable[[_T], str], cols: int = ...) -> str: ...
8587
def grey(self, text: str) -> str: ...
8688
def namelink(self, name: str, *dicts: MutableMapping[str, str]) -> str: ...
8789
def classlink(self, object: object, modname: str) -> str: ...
@@ -211,7 +213,7 @@ class ModuleScanner:
211213
def run(
212214
self,
213215
callback: Callable[[str | None, str, str], None],
214-
key: Any | None = ...,
216+
key: str | None = ...,
215217
completer: Callable[[], None] | None = ...,
216218
onerror: Callable[[str], None] | None = ...,
217219
) -> None: ...

0 commit comments

Comments
 (0)