Skip to content

Abstract class instantiation not detected when decorated by a generic method that returns type[T] #11411

@AzideCupric

Description

@AzideCupric

Describe the bug
When a class inherits from a Protocol or ABC that has abstract members and is decorated by a generic instance method that is a bound method of a generic class D[T].d(cls: type[T]) -> type[T], pyright fails to detect that the resulting class is still abstract and can be instantiated. The same abstract‑instantiation check works correctly when the decorator is a generic method on a plain class E.e[T](cls: type[T]) -> type[T].

Code or Screenshots

from abc import abstractmethod
from typing import Protocol

class A(Protocol):
    a: str

    @abstractmethod
    def test(self) -> None: ...

class D[T]:
    def d(self, cls: type[T]) -> type[T]:
        return cls

class E:
    def e[T](self, cls: type[T]) -> type[T]:
        return cls

d: D[A] = D()
e: E = E()

@d.d
class B1(A):
    pass

@e.e
class B2(A):
    pass

_ = B1()  # pyright does NOT report an error (expected: cannot instantiate abstract class)
_ = B2()  # pyright correctly reports: 'Abstract class "B2" cannot be instantiated'

VS Code extension or command-line
I'm using the pyright playground. The issue is reproducible there.

  • pyright version: 1.1.409

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions