Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add callable validation to codecs.register_error
Validate that the handler argument passed to codecs.register_error
is callable, raising TypeError with message 'handler must be callable'
if it is not. This matches CPython behavior.

This fix enables test_badregistercall in test_codeccallbacks.py to pass.
  • Loading branch information
ever0de committed Oct 30, 2025
commit 5a8d149105b24ed1e3955824fd7fc74dc78939d1
2 changes: 0 additions & 2 deletions Lib/test/test_codeccallbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,6 @@ def handle(exc):
self.assertEqual(exc.object, input)
self.assertEqual(exc.reason, "surrogates not allowed")

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_badregistercall(self):
# enhance coverage of:
# Modules/_codecsmodule.c::register_error()
Expand Down
6 changes: 5 additions & 1 deletion vm/src/stdlib/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ mod _codecs {
}

#[pyfunction]
fn register_error(name: PyStrRef, handler: PyObjectRef, vm: &VirtualMachine) {
fn register_error(name: PyStrRef, handler: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
if !handler.is_callable() {
return Err(vm.new_type_error("handler must be callable".to_owned()));
}
vm.state
.codec_registry
.register_error(name.as_str().to_owned(), handler);
Ok(())
}

#[pyfunction]
Expand Down
Loading