From 4c4f99971736605776f384b0ca04ce4ab7b84fb7 Mon Sep 17 00:00:00 2001 From: Maxime Arthaud Date: Mon, 20 Oct 2025 15:17:08 +0200 Subject: [PATCH] Add explicit definition for __repr__ and __str__ in BaseException (#14900) --- stdlib/builtins.pyi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 969d16876..1bc464933 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -2058,6 +2058,10 @@ class BaseException: def __new__(cls, *args: Any, **kwds: Any) -> Self: ... def __setstate__(self, state: dict[str, Any] | None, /) -> None: ... def with_traceback(self, tb: TracebackType | None, /) -> Self: ... + # Necessary for security-focused static analyzers (e.g, pysa) + # See https://github.com/python/typeshed/pull/14900 + def __str__(self) -> str: ... # noqa: Y029 + def __repr__(self) -> str: ... # noqa: Y029 if sys.version_info >= (3, 11): # only present after add_note() is called __notes__: list[str]