databases icon indicating copy to clipboard operation
databases copied to clipboard

typing: fetch_one: Value of type "Optional[Mapping[Any, Any]]" is not indexable

Open blueyed opened this issue 6 years ago • 1 comments

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? )

blueyed avatar Sep 13 '19 23:09 blueyed

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"

ljluestc avatar Mar 31 '24 02:03 ljluestc