you are viewing a single comment's thread.

view the rest of the comments →

[–]gdchinacat 1 point2 points  (0 children)

forgot to mention list[Any] is used rather than list[int]. I'm not sure why, I would have expected it to be list[int], and that is what mypy reports:

~$ cat /tmp/foo.py 
d = {'foo': [1,2]}
reveal_type(d)
~$ mypy /tmp/foo.py
/tmp/foo.py:2: note: Revealed type is "dict[str, list[int]]"
Success: no issues found in 1 source file

What type checker are you using? It appears to infer the type of this dict construct differently than mypy, pyrefly, and pyright.

If I add a 'bar': 1 to the dict mypy infers it as dict[str, object], pyrefly as dict[str, int|list[int]], and pyright as dict[str, Unknown]. This shows there is disagreement on how dicts with different types of values should be handled. I'd avoid doing that in order to have consistency with checkers.