gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
Jérome Perrin 2024-01-16 18:49:24 +09:00 committed by GitHub
parent 17b73ab99e
commit 04fabe22dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

@ -1051,7 +1051,11 @@ class TracebackException:
# Capture now to permit freeing resources: only complication is in the
# unofficial API _format_final_exc_line
self._str = _safe_string(exc_value, 'exception')
self.__notes__ = getattr(exc_value, '__notes__', None)
try:
self.__notes__ = getattr(exc_value, '__notes__', None)
except Exception as e:
self.__notes__ = [
f'Ignored error getting __notes__: {_safe_string(e, '__notes__', repr)}']
self._is_syntax_error = False
self._have_exc_type = exc_type is not None