I'm trying to process a dict
object, and PyCharm is giving me an unexpected type warning.
Here's a reduced example that produces the warning:
X = type("X", (), {})
def big_foo(data: Dict[str, Any]) -> Dict[str, Any]:
def little_foo(entries: Iterable[Tuple[str, Any]]) -> Iterable[Tuple[X, Any]]:
pass
def little_bar(entry: Tuple[X, Any]) -> Tuple[str, Any]:
pass
return dict(map(little_bar, little_foo(data.items())))
PyCharm is attaching this warning to the phrase data.items()
on the last line:
Expected type 'Iterable[Tuple[str, Any]]', got 'ItemsView[str, Any]' instead
I had confidently expected that dict.items()
was returning some kind of Iterable
of Tuples. Is there a good way of explaining to PyCharm what's going on? Is there actually a problem with the code?