Skip to content

ParamSpec readability simplification causes weird behavior #14799

@davidhalter

Description

@davidhalter

Bug Report

ParamSpecs are allowed to be defined in class generics like this: Foo[[int, str]]. This is allowed to be simplified for readability reasons like this: Foo[int, str]. It should however only work if a ParamSpec is the only generic type variable. In the example below however we get a weird case where this simplification is applied even though it shouldn't.

To Reproduce

from typing import Generic, TypeVar, ParamSpec

P = ParamSpec("P")
T = TypeVar("T")

class D(Generic[P, T]): ...

# Fails:
D[int, bytes, str]
# Works
D[int, bytes]

See also: https://mypy-play.net/?mypy=latest&python=3.12&gist=1c1e42d6e323cb2dcc54a7c06b440cac

Expected Behavior

In case multiple type variables or param specs are defining a class, the param spec should not be simplified and the type application above D[int, bytes] should not be allowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-paramspecPEP 612, ParamSpec, Concatenate

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions