Fixes for Pyright, closes #833

This commit is contained in:
Simon Willison 2026-08-12 13:41:33 -07:00
commit ebb04a97de
16 changed files with 109 additions and 85 deletions

View file

@ -1220,7 +1220,7 @@ def test_rows(db_path, args, expected):
{"id": 1, "age": 4, "name": "Cleo"},
{"id": 2, "age": 2, "name": "Pancakes"},
],
column_order=("id", "name", "age"),
column_order=["id", "name", "age"],
)
result = CliRunner().invoke(cli.cli, ["rows", db_path, "dogs"] + args)
assert expected == result.output.strip()

View file

@ -91,6 +91,7 @@ def test_cli_bulk_batch_size(test_db_and_path):
stdin=subprocess.PIPE,
stdout=sys.stdout,
)
assert proc.stdin is not None
# Writing one record should not commit
proc.stdin.write(b'{"id": 3, "name": "Three"}\n\n')
proc.stdin.flush()

View file

@ -577,6 +577,7 @@ def test_insert_streaming_batch_size_1(db_path):
stdin=subprocess.PIPE,
stdout=sys.stdout,
)
assert proc.stdin is not None
proc.stdin.write(b'{"name": "Azi"}\n')
proc.stdin.flush()

View file

@ -83,7 +83,8 @@ def test_autocommit_connections_are_rejected(tmpdir, autocommit):
)
def test_legacy_transaction_control_connection_is_accepted(tmpdir):
conn = sqlite3.connect(
str(tmpdir / "test.db"), autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL
str(tmpdir / "test.db"),
autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL, # type: ignore[arg-type]
)
db = Database(conn)
db.table("t").insert({"id": 1}, pk="id")

View file

@ -1182,6 +1182,7 @@ def test_works_with_pathlib_path(tmpdir):
@pytest.mark.skipif(pd is None, reason="pandas and numpy are not installed")
def test_create_table_numpy(fresh_db):
assert pd is not None
df = pd.DataFrame({"col 1": range(3), "col 2": range(3)})
fresh_db.table("pandas").insert_all(df.to_dict(orient="records"))
assert [

View file

@ -608,7 +608,7 @@ def test_foreign_key_is_immutable():
fk = ForeignKey("c", "pid", "p", "id")
with pytest.raises(dataclasses.FrozenInstanceError):
fk.table = "other"
setattr(fk, "table", "other")
def test_foreign_key_equality_and_hash_include_actions():

View file

@ -510,7 +510,7 @@ def test_view_has_no_enable_fts():
db.create_view("hello", "select 1 + 1")
# Views deliberately do not have an enable_fts() method
with pytest.raises(AttributeError):
db.view("hello").enable_fts() # type: ignore[union-attr]
db.view("hello").enable_fts() # type: ignore[attr-defined]
@pytest.mark.parametrize(

View file

@ -99,7 +99,7 @@ def test_list_mode_error_non_string_columns():
yield ["a", "b", "c"]
with pytest.raises(ValueError, match="must be a list of column name strings"):
db.table("bad").insert_all(bad_data())
db.table("bad").insert_all(bad_data()) # type: ignore[arg-type]
def test_list_mode_error_mixed_types():
@ -111,7 +111,7 @@ def test_list_mode_error_mixed_types():
yield {"id": 1, "name": "Alice"} # Should be a list, not dict
with pytest.raises(ValueError, match="must also be lists"):
db.table("bad").insert_all(bad_data())
db.table("bad").insert_all(bad_data()) # type: ignore[arg-type]
def test_list_mode_empty_after_headers():

View file

@ -86,21 +86,21 @@ def test_register_function_deterministic_tries_again_if_exception_raised(fresh_d
def test_register_function_replace(fresh_db):
@fresh_db.register_function()
def one():
def one(): # pyright: ignore[reportRedeclaration]
return "one"
assert "one" == fresh_db.execute("select one()").fetchone()[0]
# This will silently fail to replaec the function
@fresh_db.register_function()
def one(): # noqa
def one(): # pyright: ignore[reportRedeclaration]
return "two"
assert "one" == fresh_db.execute("select one()").fetchone()[0]
# This will replace it
@fresh_db.register_function(replace=True)
def one(): # noqa
def one(): # pyright: ignore[reportRedeclaration]
return "two"
assert "two" == fresh_db.execute("select one()").fetchone()[0]

View file

@ -8,7 +8,7 @@ from sqlite_utils.db import PrimaryKeyRequired
def test_upsert(use_old_upsert):
db = Database(memory=True, use_old_upsert=use_old_upsert)
table = db.table("table")
table.insert({"id": 1, "name": "Cleo"}, pk="id")
table.insert_all([{"id": 1, "name": "Cleo"}], pk="id", replace=True)
table.upsert({"id": 1, "age": 5}, pk="id", alter=True)
assert list(table.rows) == [{"id": 1, "name": "Cleo", "age": 5}]
assert table.last_pk == 1