abstract class shouldn't be considered Callable
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
An abstract class fits the typing for Callable.
To Reproduce
import abc
from typing import Callable
class A(abc.ABC):
@abc.abstractmethod
def m(self) -> None:
...
class C(A):
def m(self) -> None:
pass
def f() -> A:
return C()
def t(x: Callable[[], A]) -> None:
x()
def main() -> None:
t(f)
t(C)
t(A) # should give typing error - A is not callable because it can't be instantiated
A() # mypy correctly reports that A can't be instantiated
if __name__ == "__main__":
main()
Expected Behavior
mypy should report a typing error if an abstract class is put where a Callable should go
Actual Behavior
mypy doesn't report any error if an abstract class is put where a Callable should go
Your Environment
- Mypy version used: 0.910
- Python version used: 3.8.10
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Python example with the reported mypy version and confirm the missing diagnostic for t(A). Trace how mypy checks Callable compatibility and abstract-class instantiation, then add coverage showing that an abstract class is rejected while f and C remain accepted. Done means the expected typing error is reported for A.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100