Skip to content

Commit 5ab64b7

Browse files
authored
fix(sqlite): align adaptation protocol with CPython (#5964)
1 parent 97e85b2 commit 5ab64b7

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Lib/test/test_sqlite3/test_types.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,17 +439,13 @@ def test_missing_protocol(self):
439439
with self.assertRaises(sqlite.ProgrammingError):
440440
sqlite.adapt(1, None)
441441

442-
# TODO: RUSTPYTHON
443-
@unittest.expectedFailure
444442
def test_defect_proto(self):
445443
class DefectProto():
446444
def __adapt__(self):
447445
return None
448446
with self.assertRaises(sqlite.ProgrammingError):
449447
sqlite.adapt(1., DefectProto)
450448

451-
# TODO: RUSTPYTHON
452-
@unittest.expectedFailure
453449
def test_defect_self_adapt(self):
454450
class DefectSelfAdapt(float):
455451
def __conform__(self, _):

stdlib/src/sqlite.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,11 @@ mod _sqlite {
695695
}
696696
if let Ok(adapter) = proto.get_attr("__adapt__", vm) {
697697
match adapter.call((obj,), vm) {
698-
Ok(val) => return Ok(val),
698+
Ok(val) => {
699+
if !vm.is_none(&val) {
700+
return Ok(val);
701+
}
702+
}
699703
Err(exc) => {
700704
if !exc.fast_isinstance(vm.ctx.exceptions.type_error) {
701705
return Err(exc);
@@ -705,7 +709,11 @@ mod _sqlite {
705709
}
706710
if let Ok(adapter) = obj.get_attr("__conform__", vm) {
707711
match adapter.call((proto,), vm) {
708-
Ok(val) => return Ok(val),
712+
Ok(val) => {
713+
if !vm.is_none(&val) {
714+
return Ok(val);
715+
}
716+
}
709717
Err(exc) => {
710718
if !exc.fast_isinstance(vm.ctx.exceptions.type_error) {
711719
return Err(exc);

0 commit comments

Comments
 (0)