I'm currently plugging an Adapter into a port in a handler which can help you get an instance of that port. Here is a simple setup to reproduce:
from typing import Protocol
class SomePort(Protocol):
def caller(self):
raise NotImplementedError
class SomeAdapter:
def caller(self):
print("Called")
class SomeController:
@staticmethod
def get_instance(port: SomePort) -> SomePort:
return port()
instance = SomeController.get_instance(port=SomeAdapter)
instance.caller()
This is working just fine in code but in mypy
I'm getting the following issues:
$ mypy --version
mypy 0.931
$ mypy test/test.py
test/test.py:17: error: "SomePort" not callable
test/test.py:20: error: Argument "port" to "get_instance" of "SomeController" has incompatible type "Type[SomeAdapter]"; expected "SomePort"
anything I've misunderstood here? Running the script prints Called
just fine, but mypy is unhappy about the way I've set this up. Any help is appreciated. :)