aiofiles icon indicating copy to clipboard operation
aiofiles copied to clipboard

Deprecation warning on __aiter__

Open DavidMertz opened this issue 8 years ago • 2 comments

In a small bit of test code I trigger (I think) the changed behavior of aiter between Python 3.5 and 3.6. The code is this below, with the error. This is my very first use of aiofiles (and almost my first use of asyncio) so I'm happy to accept that I could be doing something wrong. :wink:

async def query_feed(src, queue):
    print('Starting read from {}'.format(src))
    # The file-handle itself can be non-blocking and asynchronous
    async with aiofiles.open(src) as fh:
        async for line in fh:
            await asyncio.sleep(2)
            await queue.put(line.strip())
            # print() is synchronous and completes atomically w/o control switch
            print("From feed:\t", line.strip())
DeprecationWarning: 'AsyncTextIOWrapper' implements legacy __aiter__ protocol; __aiter__ should return an asynchronous iterator, not awaitable

DavidMertz avatar Feb 16 '17 03:02 DavidMertz

Hm. I'll take a look.

Here's the relevant documentation: https://docs.python.org/3/reference/datamodel.html#asynchronous-iterators.

Tinche avatar Feb 16 '17 08:02 Tinche

aiohttp uses workaround to solve the issue depending on python version.

asvetlov avatar Feb 23 '17 18:02 asvetlov