Closed
Description
Bug Report
When matching a member-list that is declared to contain Any (I did not check other types here) with [Type() as value]
where Type
is a NamedTuple
, using that value in a seemingly correct way, will state that the type is incompatible with the needed type, despite them being the same (mypy prints the same name!).
To Reproduce
from typing import Any, NamedTuple
class T(NamedTuple):
t: list[Any]
class K(NamedTuple):
k: int
def f(t: T) -> None:
d = set[K]()
match t:
case T([K() as k]):
d.add(k)
Expected Behavior
I would expect this to be accepted (which is what happens if you run the code and also what pyright says), but in the unlikely event that this is really intentional, I would expect a better error-message than the one given.
Actual Behavior
demo.py:13: error: Argument 1 to "add" of "set" has incompatible type "K"; expected "K" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.3
- Mypy command-line flags: None or
--strict
(behavior is the same) - Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.11