gh-129354: Use PyErr_FormatUnraisable() function (#129523)

Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().

Update tests:

* test_coroutines
* test_exceptions
* test_generators
* test_struct
This commit is contained in:
Victor Stinner 2025-02-05 11:31:59 +01:00 committed by GitHub
parent dc804ffb2f
commit a25042e6d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 42 additions and 17 deletions

View file

@ -2664,14 +2664,18 @@ Our ill-behaved code should be invoked during GC:
>>> with support.catch_unraisable_exception() as cm:
... g = f()
... next(g)
... gen_repr = repr(g)
... del g
...
... cm.unraisable.err_msg == (f'Exception ignored while closing '
... f'generator {gen_repr}')
... cm.unraisable.exc_type == RuntimeError
... "generator ignored GeneratorExit" in str(cm.unraisable.exc_value)
... cm.unraisable.exc_traceback is not None
True
True
True
True
And errors thrown during closing should propagate:
@ -2776,10 +2780,12 @@ to test.
... invoke("del failed")
...
>>> with support.catch_unraisable_exception() as cm:
... l = Leaker()
... del l
... leaker = Leaker()
... del_repr = repr(type(leaker).__del__)
... del leaker
...
... cm.unraisable.object == Leaker.__del__
... cm.unraisable.err_msg == (f'Exception ignored while '
... f'calling deallocator {del_repr}')
... cm.unraisable.exc_type == RuntimeError
... str(cm.unraisable.exc_value) == "del failed"
... cm.unraisable.exc_traceback is not None