diff --git a/Lib/test/test_sqlite3/test_dbapi.py b/Lib/test/test_sqlite3/test_dbapi.py index 65821020a6..49c9764a1b 100644 --- a/Lib/test/test_sqlite3/test_dbapi.py +++ b/Lib/test/test_sqlite3/test_dbapi.py @@ -1069,8 +1069,6 @@ def test_fetchmany(self): res = self.cu.fetchmany(100) self.assertEqual(res, []) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_fetchmany_kw_arg(self): """Checks if fetchmany works with keyword arguments""" self.cu.execute("select name from test") diff --git a/stdlib/src/sqlite.rs b/stdlib/src/sqlite.rs index 8bba155612..15d3c80894 100644 --- a/stdlib/src/sqlite.rs +++ b/stdlib/src/sqlite.rs @@ -1461,6 +1461,12 @@ mod _sqlite { statement: Option>, } + #[derive(FromArgs)] + struct FetchManyArgs { + #[pyarg(any, name = "size", optional)] + size: Option, + } + #[pyclass(with(Constructor, IterNext, Iterable), flags(BASETYPE))] impl Cursor { fn new( @@ -1684,14 +1690,17 @@ mod _sqlite { #[pymethod] fn fetchmany( zelf: &Py, - max_rows: OptionalArg, + args: FetchManyArgs, vm: &VirtualMachine, ) -> PyResult> { - let max_rows = max_rows.unwrap_or_else(|| zelf.arraysize.load(Ordering::Relaxed)); + let max_rows = args + .size + .unwrap_or_else(|| zelf.arraysize.load(Ordering::Relaxed)); + let mut list = vec![]; - while let PyIterReturn::Return(row) = Self::next(zelf, vm)? { + while let PyIterReturn::Return(row) = Cursor::next(zelf, vm)? { list.push(row); - if list.len() as c_int >= max_rows { + if max_rows > 0 && list.len() as c_int >= max_rows { break; } }