From 9840c584515d25733dc6b60ac4afb608c7b0a808 Mon Sep 17 00:00:00 2001 From: Semyon Moroz Date: Sat, 10 Jan 2026 23:20:27 +0000 Subject: [PATCH] [sre_compile] Use TypeGuard for isstring (#15250) --- stdlib/sre_compile.pyi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/sre_compile.pyi b/stdlib/sre_compile.pyi index d8f0b7937..e29d63d48 100644 --- a/stdlib/sre_compile.pyi +++ b/stdlib/sre_compile.pyi @@ -2,10 +2,14 @@ from re import Pattern from sre_constants import * from sre_constants import _NamedIntConstant from sre_parse import SubPattern -from typing import Any, Final +from typing import Any, Final, Literal, overload +from typing_extensions import TypeGuard MAXCODE: Final[int] def dis(code: list[_NamedIntConstant]) -> None: ... -def isstring(obj: Any) -> bool: ... +@overload +def isstring(obj: str | bytes) -> Literal[True]: ... +@overload +def isstring(obj: object) -> TypeGuard[str | bytes]: ... def compile(p: str | bytes | SubPattern, flags: int = 0) -> Pattern[Any]: ...