Add BaseExceptionGroup for Python >= 3.11

This commit is contained in:
Adrian Garcia Badaracco 2023-05-07 15:08:43 -05:00
parent 1cdac4fde4
commit 16d333f9d0
No known key found for this signature in database
3 changed files with 14 additions and 2 deletions

View File

@ -0,0 +1 @@
Add FFI definition for `BaseExceptionGroup`, which was added in Python 3.11 by [PEP 0654](https://peps.python.org/pep-0654/).

View File

@ -103,6 +103,8 @@ pub unsafe fn PyUnicodeDecodeError_Create(
extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyExc_BaseException")]
pub static mut PyExc_BaseException: *mut PyObject;
#[cfg(Py_3_11)]
pub static mut PyExc_BaseExceptionGroup: *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyExc_Exception")]
pub static mut PyExc_Exception: *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyExc_StopAsyncIteration")]

View File

@ -493,7 +493,7 @@ impl_native_exception!(
PyExc_UnicodeError,
native_doc!("UnicodeError")
);
// these three errors need arguments, so they're too annoying to write tests for using macros...
// these four errors need arguments, so they're too annoying to write tests for using macros...
impl_native_exception!(
PyUnicodeDecodeError,
PyExc_UnicodeDecodeError,
@ -509,6 +509,12 @@ impl_native_exception!(
PyExc_UnicodeTranslateError,
native_doc!("UnicodeTranslateError", "")
);
#[cfg(Py_3_11)]
impl_native_exception!(
PyBaseExceptionGroup,
PyExc_BaseExceptionGroup,
native_doc!("BaseExceptionGroup", "")
);
impl_native_exception!(PyValueError, PyExc_ValueError, native_doc!("ValueError"));
impl_native_exception!(
PyZeroDivisionError,
@ -1028,7 +1034,10 @@ mod tests {
);
});
}
#[cfg(Py_3_11)]
test_exception!(PyBaseExceptionGroup, |_| {
PyBaseExceptionGroup::new_err(("msg", vec![PyValueError::new_err("err")]))
});
test_exception!(PyBaseException);
test_exception!(PyException);
test_exception!(PyStopAsyncIteration);