python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.22k stars 2.78k forks source link

(๐Ÿž) Sus impostor `tuple` in dict literal error message #15973

Open KotlinIsland opened 1 year ago

KotlinIsland commented 1 year ago
from typing import Any

any: Any
{"a": any}  # error: Expression type contains "Any" (has type "tuple[str, Any]")  [misc]

tuple[str, Any]

sobolevn commented 1 year ago

I cannot reproduce this error with default settings, but I think that you mean --disallow-any-expr:

ยป mypy ex.py --disallow-any-expr
ex.py:4: error: Expression type contains "Any" (has type "tuple[str, Any]")  [misc]
ex.py:4: error: Expression has type "Any" 

So, the problem is that the error message is shown twice, isn't it?

KotlinIsland commented 1 year ago

So, the problem is that the error message is shown twice, isn't it?

Well, I can see two expressions that contain Any, any and {"a": any}, but neither of these expressions are a tuple.

sobolevn commented 1 year ago

When checking {"a": any} mypy represents it as a tuple of key and value, which is kinda what it is.

KotlinIsland commented 1 year ago

When checking {"a": any} mypy represents it as a tuple of key and value, which is kinda what it is.

Yeah, that does make sense that mypy would, as an implementation detail, model this as a tuple. But in reality it's not, so the error message here doesn't make Any sense.