Skip to content

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

Merged
gvalkov merged 1 commit into
gvalkov:masterfrom
Nowa-Ammerlaan:master
Jul 17, 2022
Merged

evdev/eventio_async.py: python3.11 compatibility#174
gvalkov merged 1 commit into
gvalkov:masterfrom
Nowa-Ammerlaan:master

Conversation

@Nowa-Ammerlaan

@Nowa-Ammerlaan Nowa-Ammerlaan commented Jun 8, 2022

Copy link
Copy Markdown

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

sezanzeb commented Jun 9, 2022

Copy link
Copy Markdown
Collaborator

I'll look into this soon, thanks

@sezanzeb

sezanzeb commented Jun 11, 2022

Copy link
Copy Markdown
Collaborator

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

Comment thread evdev/eventio_async.py

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

@jonasBoss jonasBoss Jul 17, 2022

Copy link
Copy Markdown

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
Copy Markdown
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.

4 participants