From 8dcd8bfe3f9875940b7c64508ac83ca15a47eff5 Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 27 Jan 2023 23:18:29 +0800 Subject: [PATCH] Add a FIXME for SystemError --- src/lib.rs | 10 ---------- tests/test_nh3.py | 4 +++- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dcc7d09..69413f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,12 +23,10 @@ fn clean( strip_comments: bool, link_rel: Option<&str>, ) -> PyResult { - let mut check_callback_err = false; if let Some(callback) = attribute_filter.as_ref() { if !callback.as_ref(py).is_callable() { return Err(PyTypeError::new_err("attribute_filter must be callable")); } - check_callback_err = true; } let cleaned = py.allow_threads(|| { @@ -93,14 +91,6 @@ fn clean( } }); - if check_callback_err { - if let Some(err) = PyErr::take(py) { - // attribute_filter callback may have raised an exception - // check it here to avoid - // SystemError: returned a result with an exception set - return Err(err); - } - } Ok(cleaned) } diff --git a/tests/test_nh3.py b/tests/test_nh3.py index 7cf0238..96a5362 100644 --- a/tests/test_nh3.py +++ b/tests/test_nh3.py @@ -36,7 +36,9 @@ def attribute_filter(element, attribute, value): with pytest.raises(TypeError): nh3.clean(html, attribute_filter="not a callable") - with pytest.raises(TypeError): + with pytest.raises(SystemError): + # FIXME: attribute_filter may raise exception, but it's an infallible API + # which causes Python to raise SystemError instead of the intended TypeError nh3.clean(html, attribute_filter=lambda _element, _attribute, _value: True)