From 084eda7c7a86ce9ed2ffebc185294cf35ce6d374 Mon Sep 17 00:00:00 2001 From: Jiseok CHOI Date: Mon, 14 Jul 2025 00:10:53 +0900 Subject: [PATCH] fix(sqlite): align adaptation protocol with CPython --- Lib/test/test_sqlite3/test_types.py | 4 ---- stdlib/src/sqlite.rs | 12 ++++++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_sqlite3/test_types.py b/Lib/test/test_sqlite3/test_types.py index 6cbf99d6ea..53df08e999 100644 --- a/Lib/test/test_sqlite3/test_types.py +++ b/Lib/test/test_sqlite3/test_types.py @@ -439,8 +439,6 @@ def test_missing_protocol(self): with self.assertRaises(sqlite.ProgrammingError): sqlite.adapt(1, None) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_defect_proto(self): class DefectProto(): def __adapt__(self): @@ -448,8 +446,6 @@ def __adapt__(self): with self.assertRaises(sqlite.ProgrammingError): sqlite.adapt(1., DefectProto) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_defect_self_adapt(self): class DefectSelfAdapt(float): def __conform__(self, _): diff --git a/stdlib/src/sqlite.rs b/stdlib/src/sqlite.rs index cec1f04ed9..128be88747 100644 --- a/stdlib/src/sqlite.rs +++ b/stdlib/src/sqlite.rs @@ -695,7 +695,11 @@ mod _sqlite { } if let Ok(adapter) = proto.get_attr("__adapt__", vm) { match adapter.call((obj,), vm) { - Ok(val) => return Ok(val), + Ok(val) => { + if !vm.is_none(&val) { + return Ok(val); + } + } Err(exc) => { if !exc.fast_isinstance(vm.ctx.exceptions.type_error) { return Err(exc); @@ -705,7 +709,11 @@ mod _sqlite { } if let Ok(adapter) = obj.get_attr("__conform__", vm) { match adapter.call((proto,), vm) { - Ok(val) => return Ok(val), + Ok(val) => { + if !vm.is_none(&val) { + return Ok(val); + } + } Err(exc) => { if !exc.fast_isinstance(vm.ctx.exceptions.type_error) { return Err(exc);