I have the following code in test.py
:
my_dict = {"a": 1, "b": 3}
for k, v in my_dict:
print(k)
print(v)
When I run pyright pytest.py
this is not flagged as an error, even though in my understanding there is enough information to know that my_dict.__iter__
returns Iterable[keys]
and the type checker must be able to infer that the tuple unpacking would fail.
Pyright assumes that the dictionary keys are strings, which are iterable.
Tuple unpacking is a valid operation on iterables (even though it can still fail if the number of values is wrong).
If you change one of the keys to an integer (which is not iterable), you will get the error you expected.