Closed as not planned
Description
Bug Report
When using isinstance(value, Callable)
, mypy flags it as an error, claiming that Callable
is a typing special form. While it is an error to use a specialized form of Callable
such as Callable[[int], str]
, the generic class is valid for isinstance
checks.
To Reproduce
Run mypy on the following code: (playground)
from collections.abc import Callable
def check(factory: Callable) -> None:
if not isinstance(factory, Callable):
raise TypeError("'factory' is not callable")
I also tried importing Callable
from typing
instead of collections.abc
, but that doesn't make a difference.
Expected Behavior
No error is reported, as this construct executes fine and does what is expected: checking whether the object is callable.
Actual Behavior
testcase.py:4: error: Argument 2 to "isinstance" has incompatible type "<typing special form>"; expected "_ClassInfo" [arg-type]
if not isinstance(factory, Callable):
^~~~~~~~
Your Environment
- Mypy version used: 1.1.1
- Python version used: 3.10.6