From 78fba201104e1d2e155d2f725c4c3bafb4716a3f Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:58:11 +0200 Subject: [PATCH] Make `inspect.getblock` more ergonomic for common input types (#10920) --- stdlib/inspect.pyi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stdlib/inspect.pyi b/stdlib/inspect.pyi index 601d23e78..6498719df 100644 --- a/stdlib/inspect.pyi +++ b/stdlib/inspect.pyi @@ -294,6 +294,14 @@ _SourceObjectType: TypeAlias = ( def findsource(object: _SourceObjectType) -> tuple[list[str], int]: ... def getabsfile(object: _SourceObjectType, _filename: str | None = None) -> str: ... + +# Special-case the two most common input types here +# to avoid the annoyingly vague `Sequence[str]` return type +@overload +def getblock(lines: list[str]) -> list[str]: ... +@overload +def getblock(lines: tuple[str, ...]) -> tuple[str, ...]: ... +@overload def getblock(lines: Sequence[str]) -> Sequence[str]: ... def getdoc(object: object) -> str | None: ... def getcomments(object: object) -> str | None: ...