<!-- If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not the right place to seek help. Consider the following options instead: - reading the Python tutorial: https://docs.python.org/3/tutorial/ - posting in the "Users" category on discuss.python.org: https://discuss.python.org/c/users/7 - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list - searching our issue tracker (https://github.com/python/cpython/issues) to see if your problem has already been reported --> # 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 @ c6858d1e7f4cd3184d5ddea4025ad5dfc7596546. 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__`: * https://github.com/pybind/pybind11/blob/442261da585536521ff459b1457b2904895f23b4/tests/test_exceptions.py#L295 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 the `FlakyException` type ([this here](https://github.com/pybind/pybind11/blob/442261da585536521ff459b1457b2904895f23b4/include/pybind11/pytypes.h#L488)). * **With 3.12alpha6: `PyErr_Fetch()` produces the `ValueError` 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 <!-- Include as many relevant details as possible about the environment you experienced the bug in --> - CPython versions tested on: 3.12alpha6, main branch @ c6858d1e7f4cd3184d5ddea4025ad5dfc7596546 - Operating system and architecture: Debian 5.19.11 clang14, ubuntu22 gcc11 <!-- You can freely edit this text. Remove any lines you believe are unnecessary. --> <!-- gh-linked-prs --> ### Linked PRs * gh-102606 * gh-102607 * gh-102675 <!-- /gh-linked-prs -->
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#L309Followed more-or-less immediately by a
PyErr_Fetch()as e.g. here: https://github.com/pybind/pybind11/blob/442261da585536521ff459b1457b2904895f23b4/include/pybind11/pytypes.h#L482The special twist is that the exception type involved raises a
ValueErrorin its__init__:For easy reference the same code copy-pasted here:
Up to and including 3.12alpha3:
PyErr_Fetch()produces theFlakyExceptiontype (this here).With 3.12alpha6:
PyErr_Fetch()produces theValueErrortype instead.Additional detail:
Up to and including 3.12alpha3: only
PyErr_NormalizeException()hits theValueErrorinFlakyException._init__, but notPyErr_Fetch().Your environment
Linked PRs