Skip to content

Incorrect "TypeVar bound type cannot be generic" in class definition #3497

@christoph-blessing

Description

@christoph-blessing

Describe the bug

Creating a type variable that uses another type variable in its bound type creates an error even if the bound type is not generic within the scope of the type variable.

Sidenote: Not sure if this is another bug but I have set typeCheckingMode to "off" and I am still seeing this error.

To Reproduce

from abc import ABC
from typing import Generic, TypeVar

R = TypeVar("R", bound="AbstractRepository")


class AbstractRepository(ABC):
    pass


class AbstractUnitOfWork(ABC, Generic[R]):
    repo: R
    T = TypeVar("T", bound="AbstractUnitOfWork[R]")

    def commit(self: T) -> T:
        return self

I get an error saying "TypeVar bound type cannot be generic" when defining T even though AbstractUnitOfWork[R] is not a generic type in this context.

Expected behavior
No error.

VS Code extension or command-line
I am running Pyright within Neovim. The version is 1.1.248

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions