`PyErr::api_call_failed` should return a `SystemError` when no error is set

17f94e2888/Python/ceval.c (L4330-L4333)
This commit is contained in:
messense 2021-07-06 07:57:46 +08:00 committed by David Hewitt
parent 93b25edba1
commit 3ba24bee14
2 changed files with 14 additions and 3 deletions

View File

@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Change `PyErr::fetch()` to return `Option<PyErr>`. [#1728](https://github.com/PyO3/pyo3/pull/1728)
- Change `PyErr::fetch()` to return `Option<PyErr>`. [#1717](https://github.com/PyO3/pyo3/pull/1717)
## [0.14.2] - 2021-08-09

View File

@ -254,9 +254,20 @@ impl PyErr {
/// Retrieves the current error from the Python interpreter's global state.
///
/// The error is cleared from the Python interpreter.
/// Panics if no error is set
/// If no error is set, returns a `SystemError` in release mode,
/// panics in debug mode.
pub(crate) fn api_call_failed(py: Python) -> PyErr {
PyErr::fetch(py).expect("exception missing")
#[cfg(debug_assertions)]
{
PyErr::fetch(py).expect("error return without exception set")
}
#[cfg(not(debug_assertions))]
{
use crate::exceptions::PySystemError;
PyErr::fetch(py)
.unwrap_or_else(|| PySystemError::new_err("error return without exception set"))
}
}
/// Creates a new exception type with the given name, which must be of the form