How to make Mypy deal with subclasses in functions as expected
问题 I have the following code: from typing import Callable MyCallable = Callable[[object], int] MyCallableSubclass = Callable[['MyObject'], int] def get_id(obj: object) -> int: return id(obj) def get_id_subclass(obj: 'MyObject') -> int: return id(obj) def run_mycallable_function_on_object(obj: object, func: MyCallable) -> int: return func(obj) class MyObject(object): '''Object that is a direct subclass of `object`''' pass my_object = MyObject() # works just fine run_mycallable_function_on_object