mypy question

Mats Wichmann mats at wichmann.us
Fri Dec 29 09:49:17 EST 2023


On 12/29/23 05:15, Karsten Hilbert via Python-list wrote:
> Hi all,
> 
> I am not sure why mypy thinks this
> 
> gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible type "List[Dict[str, str]]"; expected
> "List[Dict[str, Union[str, List[Any], Dict[str, Any]]]]"  [arg-type]
>                      rows, idx = run_rw_queries(link_obj = conn, queries = queries, return_data = True)
>                                                                            ^~~~~~~
> 
> should be flagged. The intent is for "queries" to be
> 
> a list
> 	of dicts
> 		with keys of str
> 		and values of
> 			str OR
> 			list of anything OR
> 			dict with
> 				keys of str
> 				and values of anything
> 
> I'd have thunk list[dict[str,str]] matches that ?

Dict[str, str] means the key type and value type should both be strings, 
but in your retelling above you indicate lots of possible value types... 
actually the mypy guess seems to be a pretty good recreation of your 
psuedo-code description.


More information about the Python-list mailing list