Open
Description
Mypy uses the body of unannotated functions for inference and to understand what attributes an object has. For example:
d = {}
e = {}
def f():
d['x'] = 1
d['y'] = 2
e['y'] = 2
reveal_type(d) # dict[Any, Any]
reveal_type(e) # dict[str, int]
I couldn't find any mention of it on the docs. I think this behaviour needs to be documented. Perhaps as a separate section, to make it searchable.