Tinche / aiofiles

File support for asyncio
Apache License 2.0
2.67k stars 149 forks source link

Support for type hints #49

Open zealws opened 6 years ago

zealws commented 6 years ago

It'd be really nice to be able to use mypy against files that include aiofiles, but that's not possible now since aiofiles isn't typed.

A simple example shows that mypy --strict doesn't allow use of aiofiles.open:

$ mypy --strict main.py 
main.py:13: error: Call to untyped function "open" in typed context

Here's the code:

#!/usr/bin/env python
import aiofiles
import asyncio

def main() -> None:
    el = asyncio.get_event_loop()
    el.run_until_complete(async_main())

async def async_main() -> None:
    async with aiofiles.open('test_aiofiles', 'wb') as f:
        await f.write(b'Hello, world!\n')

if __name__ == '__main__':
    main()
Tinche commented 6 years ago

Feel like submitting a pull request? You'd need to use the old typing style (e.g. in comments) but it shouldn't be too difficult.

graingert commented 5 years ago

@Tinche Python has supported function annotations since https://www.python.org/dev/peps/pep-3107/

Tinche commented 5 years ago

As long as the tests pass on our current platforms, I'll merge it in :)

davesteele commented 2 years ago

Mitigations addressed in the Debian bug report:

https://bugs.debian.org/994932

Tinche commented 2 years ago

Hm looks like someone wrote stubs for us?

pip install types-aiofiles

Would this be enough to close this issue?

graingert commented 2 years ago

It would be more convenient if you merged them in and added a py.typed

davesteele commented 2 years ago

Yes, that is enough.

vbraun commented 2 years ago

types-aiofiles is a nice first step but rather incomplete

cpvandehey commented 1 year ago

bump