pyright
pyright copied to clipboard
sequence pattern on NamedTuple infers `tuple` type
Describe the bug
In a match statement, when a sequence pattern is applied to a NamedTuple variable, the variable is inferred as a tuple rather than it's original NamedTuple type.
Code or Screenshots
from typing import NamedTuple
class A(NamedTuple):
x: int
y: int
def f(a: A):
...
def m(a: A):
match a:
case _, _:
f(a)
nt.py
nt.py:13:15 - error: Argument of type "tuple[int, int]" cannot be assigned to parameter "a" of type "A" in function "f"
"tuple[int, int]" is not assignable to "A" (reportArgumentType)
1 error, 0 warnings, 0 informations
workaround: use case A(_, _): instead of case _, _:
VS Code extension or command-line
command-line tool, 1.1.408