Description
Bug report
While testing pybind11 with Python 3.12alpha6 I ran into what looks like a PyErr_Fetch()
behavior change. I also tried with the main branch @ c6858d1.
I think the issue reduces to:
-
PyErr_SetObject()
as e.g. here: https://github.com/pybind/pybind11/blob/442261da585536521ff459b1457b2904895f23b4/tests/test_exceptions.cpp#L309 -
Followed more-or-less immediately by a
PyErr_Fetch()
as e.g. here: https://github.com/pybind/pybind11/blob/442261da585536521ff459b1457b2904895f23b4/include/pybind11/pytypes.h#L482
The special twist is that the exception type involved raises a ValueError
in its __init__
:
For easy reference the same code copy-pasted here:
class FlakyException(Exception):
def __init__(self, failure_point):
if failure_point == "failure_point_init":
raise ValueError("triggered_failure_point_init")
self.failure_point = failure_point
-
Up to and including 3.12alpha3:
PyErr_Fetch()
produces theFlakyException
type (this here). -
With 3.12alpha6:
PyErr_Fetch()
produces theValueError
type instead.
Additional detail:
Up to and including 3.12alpha3: only PyErr_NormalizeException()
hits the ValueError
in FlakyException._init__
, but not PyErr_Fetch()
.
Your environment
- CPython versions tested on: 3.12alpha6, main branch @ c6858d1
- Operating system and architecture: Debian 5.19.11 clang14, ubuntu22 gcc11