First of all, I'm aware it is developers' responsibility to make sure your define your method as a coroutine when implementing child class
class MyBase(ABC):
@abstractclassmethod
def the_coroutine(self):
"""
I want this to be a coroutine
"""
class ImplBaseA(MyBase):
async def the_coroutine(self):
return "awaited"
class ImplBaseB(MyBase):
def the_coroutine(self):
# some condition that happens quite often
if True:
raise ValueError("From the first glance I was even awaited")
return "not the coroutine"
But how to prevent this issue in the code from occurring?
await a.the_coroutine()
# When inspecting the code it seems like it does the right thing
await b.the_coroutine()
# and when raising exception it really does
Should I use mypy or some similar tool? What's the pythonic way of making sure implementation is coroutine only (regular function only)?