I've been playing around with the plugin interface, and was hitting a strange error with the following (minimal) example plugin:
from typing import Callable, Optional, Type
from mypy.plugin import MethodContext, Plugin
class DummyPlugin(Plugin):
def get_method_hook(
self, fullname: str) -> Optional[Callable[[MethodContext], Type]]:
return dummy_callback
def dummy_callback(ctx: MethodContext) -> Type:
return ctx.default_return_type
plugin = lambda _: DummyPlugin
dummy_plugin.py:8: error: Return type of "get_method_hook" incompatible with supertype "Plugin"
dummy_plugin.py:14: error: Incompatible return value type (got "Type", expected Type[Any])
It took a while of staring confusedly at my code to realise that the fix is quite simple:
--- dummy_plugin.py.old 2017-08-22 14:58:55.739834119 -0400
+++ dummy_plugin.py 2017-08-22 14:59:11.407829264 -0400
@@ -1,6 +1,7 @@
-from typing import Callable, Optional, Type
+from typing import Callable, Optional
from mypy.plugin import MethodContext, Plugin
+from mypy.types import Type
class DummyPlugin(Plugin):
It would be good to have a bit more information about where the types come from in this case.