pyright
pyright copied to clipboard
namedtuple `typename` and `field_names` keyword forms bound positionally
Describe the bug
typename and field_names of collections.namedtuple are positional-or-keyword, but pyright takes the class name from the call's first argument and the fields from its second, even when those are keyword arguments. When a keyword argument puts either one in another position, the class gets the wrong name or fields, or a constructor that accepts any arguments.
This came up in https://github.com/microsoft/pyright/pull/11930#pullrequestreview-5962993274.
Code or Screenshots
from collections import namedtuple
A = namedtuple("A", rename=True, field_names="x y")
reveal_type(A.__new__)
B = namedtuple(field_names="x y", typename="B")
reveal_type(B)
:4:13 - information: Type of "A.__new__" is "(*args: Any, **kwargs: Any) -> Self@A"
:7:13 - information: Type of "B" is "type[x y]"
VS Code extension or command-line Command-line, pyright 1.1.415