Skip to content

Pylance doesn't color classes' generic types for 3.12 syntax #7593

@mtsokol

Description

@mtsokol

As the title says the new generic class syntax seems to not be supported class MyClass[T]:, contrary to the previous formula class MyClass(Generic[T]):.

New syntax: https://docs.python.org/3/library/typing.html#typing.TypeVar

Environment data

  • Pylance version: 2025.8.2
  • OS and version: MacOS 15.6.1
  • Python version: Python 3.12.11

Code Snippet

from typing import TypeVar, Generic

T = TypeVar("T", int, bytes)


class AA[T]:
    def __init__(self, arg: T):
        self.arg: T = arg


class BB(Generic[T]):
    def __init__(self, arg: T):
        self.arg: T = arg

Expected behavior

T type in both class versions should be recognized and colored in light blue.

Actual behavior

With the new syntax (supported since 3.12) the T isn't recognized (which is what white color suggest).

Image

Metadata

Metadata

Assignees

Labels

ai-triage-respondedIndicate whether the AI triage agent has responded to this issue.team needs to reproduceIssue has not been reproduced yet

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions