[3.11] gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359) (#114118)

This commit is contained in:
Jérome Perrin 2024-01-20 05:35:57 +09:00 committed by GitHub
parent a4ad7a0ac5
commit 20f7cf2c7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 52 additions and 2 deletions

View file

@ -733,7 +733,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)}']
if exc_type and issubclass(exc_type, SyntaxError):
# Handle SyntaxError's specially