[3.10] bpo-45826: Fix a crash in suggestions.c by checking for traceback is None (GH-29590) (GH-29602)

(cherry picked from commit 5d90c467c0)

Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
This commit is contained in:
Łukasz Langa 2021-11-18 01:28:04 +01:00 committed by GitHub
parent 563e45875a
commit 8eabe60108
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 3 deletions

View file

@ -1885,6 +1885,37 @@ def foo():
self.assertNotIn("something", err.getvalue())
def test_issue45826(self):
# regression test for bpo-45826
def f():
with self.assertRaisesRegex(NameError, 'aaa'):
aab
try:
f()
except self.failureException:
with support.captured_stderr() as err:
sys.__excepthook__(*sys.exc_info())
self.assertIn("aab", err.getvalue())
def test_issue45826_focused(self):
def f():
try:
nonsense
except BaseException as E:
E.with_traceback(None)
raise ZeroDivisionError()
try:
f()
except ZeroDivisionError:
with support.captured_stderr() as err:
sys.__excepthook__(*sys.exc_info())
self.assertIn("nonsense", err.getvalue())
self.assertIn("ZeroDivisionError", err.getvalue())
class AttributeErrorTests(unittest.TestCase):
def test_attributes(self):