Skip to content

Commit 08b5d92

Browse files
committed
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.
1 parent 11e7d90 commit 08b5d92

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

stdlib/builtins.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,9 @@ class BaseException:
20582058
def __new__(cls, *args: Any, **kwds: Any) -> Self: ...
20592059
def __setstate__(self, state: dict[str, Any] | None, /) -> None: ...
20602060
def with_traceback(self, tb: TracebackType | None, /) -> Self: ...
2061+
# Necessary for security-focused static analyzers (e.g, pysa)
2062+
def __str__(self) -> str: ... # noqa: Y029
2063+
def __repr__(self) -> str: ... # noqa: Y029
20612064
if sys.version_info >= (3, 11):
20622065
# only present after add_note() is called
20632066
__notes__: list[str]

0 commit comments

Comments
 (0)