-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-named-tupletopic-paramspecPEP 612, ParamSpec, ConcatenatePEP 612, ParamSpec, Concatenate
Description
Bug Report
NamedTuple parametrized with a ParamSpec can't be used as an annotation.
It's probably easiest to look at my repro to see what I mean.
I know that generic support for NamedTuple is new-ish as of 3.11, but I couldn't find any documentation that says ParamSpec is somehow still unsupported.
To Reproduce
from collections.abc import Callable
from typing import NamedTuple
class T[**P](NamedTuple):
plugin: Callable[P, int]
def f[**P](a: T[P]) -> None:
passI note that if I change T from a NamedTuple to a dataclass, there's no error.
Expected Behavior
$ mypy t.py
Success: no issues found in 1 source fileActual Behavior
$ mypy t.py
t.py:9: error: Invalid location for ParamSpec "P" [valid-type]
t.py:9: note: You can use ParamSpec as the first argument to Callable, e.g., "Callable[P, int]"
Found 1 error in 1 file (checked 1 source file)The error is referring to the T[P] annotation.
Your Environment
- Mypy version used:
mypy 1.17.1 (compiled: yes) - Mypy command-line flags:
mypy - Mypy configuration options from
mypy.ini(and other config files): none - Python version used:
Python 3.13.5
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-named-tupletopic-paramspecPEP 612, ParamSpec, ConcatenatePEP 612, ParamSpec, Concatenate