mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
sqlite: Throw TypeError when callable is not callable (#4923)
This commit is contained in:
2
Lib/test/test_sqlite3/test_hooks.py
vendored
2
Lib/test/test_sqlite3/test_hooks.py
vendored
@@ -36,8 +36,6 @@ class CollationTests(unittest.TestCase):
|
||||
with self.assertRaises(TypeError):
|
||||
con.create_collation(None, lambda x, y: (x > y) - (x < y))
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_create_collation_not_callable(self):
|
||||
con = sqlite.connect(":memory:")
|
||||
with self.assertRaises(TypeError) as cm:
|
||||
|
||||
@@ -1107,7 +1107,7 @@ mod _sqlite {
|
||||
) -> PyResult<()> {
|
||||
let name = name.to_cstring(vm)?;
|
||||
let db = self.db_lock(vm)?;
|
||||
let Some(data )= CallbackData::new(callable, vm) else {
|
||||
let Some(data) = CallbackData::new(callable.clone(), vm) else {
|
||||
unsafe {
|
||||
sqlite3_create_collation_v2(db.db, name.as_ptr(), SQLITE_UTF8, null_mut(), None, None);
|
||||
}
|
||||
@@ -1115,6 +1115,10 @@ mod _sqlite {
|
||||
};
|
||||
let data = Box::into_raw(Box::new(data));
|
||||
|
||||
if !callable.is_callable() {
|
||||
return Err(vm.new_type_error("parameter must be callable".to_owned()));
|
||||
}
|
||||
|
||||
let ret = unsafe {
|
||||
sqlite3_create_collation_v2(
|
||||
db.db,
|
||||
|
||||
Reference in New Issue
Block a user