Abstract class instantiation not detected when decorated by a generic method that returns type[T]
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**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**
```python
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](https://pyright-play.net/). The issue is reproducible there.
- pyright version: 1.1.409
Contributor guide
Research direction
Start with the provided pyright playground reproduction and compare the abstract-instantiation diagnostics for B1 and B2. Done means the generic bound-method decorator case reports that B1 cannot be instantiated, matching the existing diagnostic for B2, with a regression test covering the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100