databases
databases copied to clipboard
typing: fetch_one: Value of type "Optional[Mapping[Any, Any]]" is not indexable
Running mypy on the tests shows:
Value of type "Optional[Mapping[Any, Any]]" is not indexable
with https://github.com/encode/databases/blob/88b381ae33bcb417b76b8df9149742cbbcc253b5/tests/test_databases.py#L146
This means the typing annotations should be fixed and that mypy should also run on tests.
(given that this is done via custom scripts together with the tests etc I'm not touching it myself - it would be good to have a separate qa/lint env for that - i.e. why is mypy run with test and lint scripts, and why is there tox not being used for it still? )
from typing import Any, Optional, Mapping
async def test_fetch_one() -> None:
query = "SELECT * FROM test_table WHERE id = :id"
values = {"id": 1}
result: Optional[Mapping[str, Any]] = await database.fetch_one(query=query, values=values)
assert result is not None
assert result["text"] == "example1"