Skip to content

Commit 6956b67

Browse files
Clarify fetchmany rejection message: "non-negative" instead of ">= 0"
The rejection message read awkwardly at the point it fires: the guard only triggers when the caller passes a negative size, so "must be >= 0, got -5" reads like a contradiction. "non-negative" describes the same constraint but scans correctly in the rejection context. Updated the sync and async cursors together and adjusted the existing regex pin test. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 284add0 commit 6956b67

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/dqlitedbapi/aio/cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async def fetchmany(self, size: int | None = None) -> list[tuple[Any, ...]]:
199199
if size < 0:
200200
# See sync Cursor.fetchmany: silently returning [] on a
201201
# negative size hides caller bugs.
202-
raise ProgrammingError(f"fetchmany size must be >= 0, got {size}")
202+
raise ProgrammingError(f"fetchmany size must be non-negative, got {size}")
203203

204204
result: list[tuple[Any, ...]] = []
205205
for _ in range(size):

src/dqlitedbapi/cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def fetchmany(self, size: int | None = None) -> list[tuple[Any, ...]]:
371371
# Previously ``range(-5)`` silently returned [] — hid caller
372372
# bugs. ``arraysize`` setter already validates >= 1; mirror
373373
# that here.
374-
raise ProgrammingError(f"fetchmany size must be >= 0, got {size}")
374+
raise ProgrammingError(f"fetchmany size must be non-negative, got {size}")
375375

376376
result: list[tuple[Any, ...]] = []
377377
for _ in range(size):

tests/test_dbapi_hardening.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _check_thread(self) -> None: ...
113113
cursor = Cursor(_FakeConn()) # type: ignore[arg-type]
114114
cursor._description = [("x", None, None, None, None, None, None)]
115115
cursor._rows = [(1,), (2,)]
116-
with pytest.raises(ProgrammingError, match=">= 0"):
116+
with pytest.raises(ProgrammingError, match="non-negative"):
117117
cursor.fetchmany(-5)
118118
# 0 is allowed per PEP 249.
119119
assert cursor.fetchmany(0) == []
@@ -129,7 +129,7 @@ class _FakeAsyncConn:
129129
cursor._rows = [(1,), (2,)]
130130

131131
async def _run() -> None:
132-
with pytest.raises(ProgrammingError, match=">= 0"):
132+
with pytest.raises(ProgrammingError, match="non-negative"):
133133
await cursor.fetchmany(-3)
134134
assert await cursor.fetchmany(0) == []
135135

0 commit comments

Comments
 (0)