Skip to content
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

Convert to async/await syntax #12614

Closed
balloob opened this issue Feb 23, 2018 · 2 comments
Closed

Convert to async/await syntax #12614

balloob opened this issue Feb 23, 2018 · 2 comments

Comments

@balloob
Copy link
Member

balloob commented Feb 23, 2018

We're on Python 3.5 so it's time to let go of @asyncio.coroutine. Migration of a piece of code is simple as they are functionally compatible:

  • Remove @asyncio.coroutine decorator
  • Add async before function definition: async def async_start(self):
  • Replace all yield from with await

For now, let's focus on updating all pieces of code for which we have tests. Let's not update the tests and the code in the same PR. Instead, do 1 PR for the code, 1 PR for the tests. That way we know we don't break things.

If you see an error that you can't await a generator context, it's because you're awaiting a function that doesn't have @asyncio.coroutine as the first decorator above the function name. In such cases, just replace decorator with async and you're good 👍

Python 3.5 also does a better job in warning when async methods have been called but not awaited. When you run py.test locally, note these warnings and please fix them 👍

To kick it off, here is a conversion of the core: #12610

@pvizeli
Copy link
Member

pvizeli commented Feb 23, 2018

Also all asyncio.Locks change the syntax while they support async context manager syntax.

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@balloob balloob closed this as completed May 29, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Oct 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants