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

evdev/eventio_async.py: python3.11 compatibility #174

Merged
merged 1 commit into from Jul 17, 2022
Merged

evdev/eventio_async.py: python3.11 compatibility #174

merged 1 commit into from Jul 17, 2022

Conversation

AndrewAmmerlaan
Copy link
Contributor

@AndrewAmmerlaan AndrewAmmerlaan commented Jun 8, 2022

From the Python 3.11 Changelog:

The @asyncio.coroutine decorator enabling legacy generator-based coroutines to be compatible with async/await code. The function has been deprecated since Python 3.8 and the removal was initially scheduled for Python 3.10. Use async def instead. (Contributed by Illia Volochii in bpo-43216.)

This small change should make things work with python 3.11, the tests are passing for me.

Signed-off-by: Andrew Ammerlaan andrewammerlaan@gentoo.org

Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
@sezanzeb
Copy link
Collaborator

sezanzeb commented Jun 9, 2022

I'll look into this soon, thanks

@sezanzeb
Copy link
Collaborator

sezanzeb commented Jun 11, 2022

This doesn't work anymore with your change in Python 3.10.4:

import evdev
import asyncio

async def main():
    keyboard = evdev.InputDevice("/dev/input/event7")
    async for event in keyboard.async_read_loop():
        print(event.type, event.code, event.value)

loop = asyncio.new_event_loop()
loop.run_until_complete(main())

python-evdev tests are very rudimentary afaik. I found this by running input-remappers tests

@@ -85,8 +85,7 @@ def __next__(self):
def __aiter__(self):
return self

@asyncio.coroutine
def __anext__(self):
async def __anext__(self):
Copy link

@jonasBoss jonasBoss Jul 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the python docs __anext__ should return a Awaitable which this function already does. So there is no need to use the async keyword. async def would wrap the whole function again inside a awaitable making it necessary to await this function twice.

Suggested change
async def __anext__(self):
def __anext__(self):

As for the @asyncio.coroutine: I think this was never needed as it was meant for generator-based coroutines which this function is not.

I did some quick tests with python3.8 and 3.10. This seems to work fine.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. I think this is the correct solution indeed. Will release a new version asap. Thanks!

@gvalkov gvalkov merged commit 1a51829 into gvalkov:master Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants