Skip to content

Commit 91d55b8

Browse files
fix: resolve type checking errors in DuckDB tests
- Add pyright: ignore comments for intentional _connection access in tests - Add null assertions for fetchone() results - Move type ignore comments outside SQL strings to avoid DuckDB parse errors - All 406 DuckDB tests now passing Co-authored-by: William Easton <strawgate@users.noreply.github.com>
1 parent c057e30 commit 91d55b8

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

key-value/key-value-aio/tests/stores/duckdb/test_duckdb.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,29 @@ async def test_native_sql_queryability(self):
7979
FROM kv_entries
8080
WHERE collection = 'products'
8181
ORDER BY key
82-
""").fetchall()
82+
""").fetchall() # pyright: ignore[reportPrivateUsage]
8383

8484
assert len(result) == 2
8585
assert result[0][0] == "item1"
8686
assert result[0][1] == '"Widget"' # JSON strings are quoted
8787
assert result[1][0] == "item2"
8888

8989
# Query by expiration timestamp
90-
result = store._connection.execute("""
90+
count_result = store._connection.execute("""
9191
SELECT COUNT(*)
9292
FROM kv_entries
9393
WHERE expires_at > now() OR expires_at IS NULL
94-
""").fetchone()
94+
""").fetchone() # pyright: ignore[reportPrivateUsage]
9595

96-
assert result[0] == 3 # All 3 entries should not be expired
96+
assert count_result is not None
97+
assert count_result[0] == 3 # All 3 entries should not be expired
9798

9899
# Query metadata columns directly
99100
result = store._connection.execute("""
100101
SELECT key, ttl, created_at IS NOT NULL as has_created
101102
FROM kv_entries
102103
WHERE collection = 'products' AND ttl > 3600
103-
""").fetchall()
104+
""").fetchall() # pyright: ignore[reportPrivateUsage]
104105

105106
assert len(result) == 1 # Only item2 has ttl > 3600
106107
assert result[0][0] == "item2"
@@ -120,7 +121,7 @@ async def test_text_mode_storage(self):
120121
SELECT value_json, value_dict, typeof(value_json) as json_type, typeof(value_dict) as dict_type
121122
FROM kv_entries
122123
WHERE collection = 'test' AND key = 'key1'
123-
""").fetchone()
124+
""").fetchone() # pyright: ignore[reportPrivateUsage]
124125

125126
assert result is not None
126127
value_json, value_dict, json_type, _dict_type = result
@@ -235,7 +236,7 @@ async def test_custom_table_name(self):
235236
SELECT key, collection
236237
FROM {custom_table}
237238
WHERE key = 'key1'
238-
""").fetchone() # noqa: S608
239+
""").fetchone() # pyright: ignore[reportPrivateUsage] # noqa: S608
239240

240241
assert result is not None
241242
assert result[0] == "key1"
@@ -246,7 +247,7 @@ async def test_custom_table_name(self):
246247
SELECT table_name
247248
FROM information_schema.tables
248249
WHERE table_name = 'kv_entries'
249-
""").fetchall()
250+
""").fetchall() # pyright: ignore[reportPrivateUsage]
250251

251252
assert len(tables) == 0
252253

@@ -258,29 +259,31 @@ async def test_native_vs_stringified_storage(self):
258259
store_native = DuckDBStore(native_storage=True)
259260
await store_native.put(collection="test", key="key1", value={"name": "native"})
260261

261-
result = store_native._connection.execute("""
262+
result_native = store_native._connection.execute("""
262263
SELECT value_dict, value_json
263264
FROM kv_entries
264265
WHERE key = 'key1'
265-
""").fetchone()
266+
""").fetchone() # pyright: ignore[reportPrivateUsage]
266267

267-
assert result[0] is not None # value_dict should be populated
268-
assert result[1] is None # value_json should be NULL
268+
assert result_native is not None
269+
assert result_native[0] is not None # value_dict should be populated
270+
assert result_native[1] is None # value_json should be NULL
269271

270272
await store_native.close()
271273

272274
# Stringified storage
273275
store_string = DuckDBStore(native_storage=False)
274276
await store_string.put(collection="test", key="key2", value={"name": "stringified"})
275277

276-
result = store_string._connection.execute("""
278+
result_string = store_string._connection.execute("""
277279
SELECT value_dict, value_json
278280
FROM kv_entries
279281
WHERE key = 'key2'
280-
""").fetchone()
282+
""").fetchone() # pyright: ignore[reportPrivateUsage]
281283

282-
assert result[0] is None # value_dict should be NULL
283-
assert result[1] is not None # value_json should be populated
284+
assert result_string is not None
285+
assert result_string[0] is None # value_dict should be NULL
286+
assert result_string[1] is not None # value_json should be populated
284287

285288
await store_string.close()
286289

0 commit comments

Comments
 (0)