From c11986f3e180fd07314354ec273687acbea56f24 Mon Sep 17 00:00:00 2001 From: Maxime Arthaud Date: Mon, 20 Oct 2025 14:38:13 +0200 Subject: [PATCH] Add explicit definition for __repr__ and __str__ in BaseException Taint analysis tools such as Pysa might want to mark `BaseException.__str__` and `BaseException.__repr__` as a source. However, since those methods are inherited, this is not possible. Making the definition explicit fixes the problem. --- stdlib/builtins.pyi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 969d1687611c..1bc46493338c 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]