mypy question
Mats Wichmann
mats at wichmann.us
Fri Dec 29 13:04:59 EST 2023
On 12/29/23 08:02, Karsten Hilbert via Python-list wrote:
>> Dict[str, str] means the key type and value type should both be strings,
>
> Indeed, I know that much, list[dict[str, str]] is what is getting
> passed in in this particular invocation of run_rw_queries().
>
> For what it's worth here's the signature of that function:
>
> def run_rw_queries (
> link_obj:_TLnkObj=None,
> queries:list[dict[str, str | list | dict[str, Any]]]=None,
> end_tx:bool=False,
> return_data:bool=None,
> get_col_idx:bool=False,
> verbose:bool=False
> ) -> tuple[list[dbapi.extras.DictRow], dict[str, int] | None]:
>
> Given that I would have thought that passing in
> list[dict[str, str]] for "queries" ought to be type safe.
> Mypy indicates otherwise which I am not grokking as to why.
ah... didn't grok what you were asking, sorry - ignore my attempt then.
So you are passing something that has been typed more narrowly than the
function parameter. Can you use a TypeGuard here?
More information about the Python-list
mailing list