-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check async function ? #15
Comments
Hmm. I think it's an interesting question whether interface should reject The contract that you probably care about as a consumer of For example, this would be probably be a valid implementation of class MyAwaitable:
def __init__(self, value):
self.value = value
def __await__(self):
return self.value
yield
class ValidFoo(interface.implements(IFoo)):
def do_async(self):
return MyAwaitable(5) |
I agree, however this is a pretty unorthodox way of writting async function... well orthodoxy about async function have changed a lot since Python 3.4, but now async/await have landed and are supported by all major frameworks (asyncio, twisted, tornado, curio, trio etc.) So considering your example, I would expect it to be implemented like: class ValidFoo(interface.implements(IFoo)):
async def do_async(self):
return await MyAwaitable(5) This way we respect the async interface requirement, even if we use a custom awaitable. On a more theoretical point of view, async/await has been designed to easily recognize asynchronous blocks and synchronization points (otherwise generator with yield would have done the job fine ^^). I would say defining interface share a similar goal as another way of making Python code more explicit (as opposed to just have something that runs). |
@touilleMan I buy that argument (sorry for the long delay on replying). I took a crack at implementing this in #17 if you want to take a look. |
It seems the module currently don't make difference between sync and async functions:
The text was updated successfully, but these errors were encountered: