You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
fromcollections.abcimportCallabledefcheck(factory: Callable) ->None:
ifnotisinstance(factory, Callable):
raiseTypeError("'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
The text was updated successfully, but these errors were encountered:
Bug Report
When using
isinstance(value, Callable)
, mypy flags it as an error, claiming thatCallable
is a typing special form. While it is an error to use a specialized form ofCallable
such asCallable[[int], str]
, the generic class is valid forisinstance
checks.To Reproduce
Run mypy on the following code: (playground)
I also tried importing
Callable
fromtyping
instead ofcollections.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
Your Environment
The text was updated successfully, but these errors were encountered: