Skip to content

Commit

Permalink
Add a FIXME for SystemError
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jan 27, 2023
1 parent 72be3e6 commit 8dcd8bf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
10 changes: 0 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ fn clean(
strip_comments: bool,
link_rel: Option<&str>,
) -> PyResult<String> {
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(|| {
Expand Down Expand Up @@ -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: <function clean> returned a result with an exception set
return Err(err);
}
}
Ok(cleaned)
}

Expand Down
4 changes: 3 additions & 1 deletion tests/test_nh3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 8dcd8bf

Please sign in to comment.