Tinche / aiofiles

File support for asyncio
Apache License 2.0
2.66k stars 150 forks source link

mypy issue when iterating on a file line-by-line #105

Open pietrodn opened 3 years ago

pietrodn commented 3 years ago

mypy type checking fails on the following script:

import asyncio
from pathlib import Path

import aiofiles

FILENAME = Path.home() / ".zshrc"

async def main() -> None:
    async with aiofiles.open(FILENAME, "r") as input_fd:
        async for line in input_fd:
            print(line)

if __name__ == '__main__':
    asyncio.run(main())

The error:

$ mypy scratch.py

scratch.py:10: error: "Coroutine[Any, Any, Iterator[str]]" has no attribute "__anext__"
Found 1 error in 1 file (checked 1 source file)

I'm using mypy 0.812 (the latest version as of today) and Python 3.9.4. The errors appears with the default mypy configuration.

Akuli commented 3 years ago

aiofiles doesn't have type hints. They are maintained separately at typeshed: https://github.com/python/typeshed/tree/master/stubs/aiofiles