From 37ee3cf73daa9f2cd384394aa6c0cb825826da63 Mon Sep 17 00:00:00 2001 From: Jiseok CHOI Date: Wed, 16 Jul 2025 00:02:18 +0900 Subject: [PATCH] Correctly handle `None` for protocol in `adapt(..)` --- Lib/test/test_sqlite3/test_types.py | 2 -- stdlib/src/sqlite.rs | 9 ++++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_sqlite3/test_types.py b/Lib/test/test_sqlite3/test_types.py index 53df08e999..6231882351 100644 --- a/Lib/test/test_sqlite3/test_types.py +++ b/Lib/test/test_sqlite3/test_types.py @@ -433,8 +433,6 @@ def test_missing_adapter(self): with self.assertRaises(sqlite.ProgrammingError): sqlite.adapt(1.) # No float adapter registered - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_missing_protocol(self): with self.assertRaises(sqlite.ProgrammingError): sqlite.adapt(1, None) diff --git a/stdlib/src/sqlite.rs b/stdlib/src/sqlite.rs index 4e9620eeab..c5b71eb675 100644 --- a/stdlib/src/sqlite.rs +++ b/stdlib/src/sqlite.rs @@ -732,7 +732,14 @@ mod _sqlite { alt: OptionalArg, vm: &VirtualMachine, ) -> PyResult { - // TODO: None proto + if matches!(proto, OptionalArg::Present(None)) { + return if let OptionalArg::Present(alt) = alt { + Ok(alt) + } else { + Err(new_programming_error(vm, "can't adapt".to_owned())) + }; + } + let proto = proto .flatten() .unwrap_or_else(|| PrepareProtocol::class(&vm.ctx).to_owned());