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

This commit is contained in:
Jérome Perrin 2024-01-22 02:12:17 +09:00 committed by GitHub
parent afefa4a74c
commit 00e8c9ce9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 53 additions and 2 deletions

View file

@ -1654,6 +1654,21 @@ class BaseExceptionReportingTests:
err_msg = "b'please do not show me as numbers'"
self.assertEqual(self.get_report(e), vanilla + err_msg + '\n')
# an exception with a broken __getattr__ raising a non expected error
class BrokenException(Exception):
broken = False
def __getattr__(self, name):
if self.broken:
raise ValueError(f'no {name}')
raise AttributeError(name)
e = BrokenException(123)
vanilla = self.get_report(e)
e.broken = True
self.assertEqual(
self.get_report(e),
vanilla + "Ignored error getting __notes__: ValueError('no __notes__')\n")
def test_exception_with_multiple_notes(self):
for e in [ValueError(42), SyntaxError('bad syntax')]:
with self.subTest(e=e):