from typing import Callable
class SuperClass:
pass
class SubClass(SuperClass):
pass
def a_function(another_function: Callable[[SuperClass], None]):
pass
def superclass_callable(temp: SuperClass) -> None:
pass
def subclass_callable(temp: SubClass) -> None:
pass
a_function(superclass_callable)
a_function(subclass_callable)
superclass_callable(SuperClass())
superclass_callable(SubClass())
In the code above, PyCharm is highlighting a_function(subclass_callable)
and telling me Expected type '(SuperClass) -> None, got '(temp: SubClass) -> None' instead
. Everything I've seen in my searches says that the type hinting should accept subclasses, so I can't figure out what's going wrong here. PyCharm doesn't complain if the function just takes the super class or a list of them as an argument, only if it's a Callable, as far as I've seen. For example, neither of the last two lines has a problem.