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

Mypy reports incorrect errors when making async call #9739

Closed
julaudo opened this issue Nov 20, 2020 · 3 comments
Closed

Mypy reports incorrect errors when making async call #9739

julaudo opened this issue Nov 20, 2020 · 3 comments
Labels
bug mypy got something wrong

Comments

@julaudo
Copy link

julaudo commented Nov 20, 2020

Bug Report

Mypy sometimes reports incorrect errors when using async/async with
One example is when using aiofiles.open
These errors appeared when upgrading from 0.782 to 0.790

To Reproduce

The following code reproduces the errors:

import asyncio
import aiofiles


async def test_async_with() -> None:
    async with aiofiles.open('./file.txt', 'rb') as file:
        print(type(file))


async def test_async() -> None:
    file = await aiofiles.open('./file.txt', 'rb')
    print(type(file))

loop = asyncio.get_event_loop()
loop.run_until_complete(test_async_with())
loop.run_until_complete(test_async())

Expected Behavior

No error should be reported

Actual Behavior

2 errors in test_async_with:

test.py:6: error: "AsyncBufferedReader" has no attribute "__aenter__"
test.py:6: error: "AsyncBufferedReader" has no attribute "__aexit__"

1 error in test_async:
test.py:11: error: Incompatible types in "await" (actual type "AsyncBufferedReader", expected type "Awaitable[Any]")

Your Environment

  • Mypy version used: 0.790
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.6.0
  • Operating system and version: Windows 10
@julaudo julaudo added the bug mypy got something wrong label Nov 20, 2020
@JelleZijlstra
Copy link
Member

This sounds like an issue with the aiofiles stubs. Could you try to reproduce this issue in a way that doesn't rely on third-party packages?

@hauntsaninja
Copy link
Collaborator

In particular, typeshed has since made improvements to the aiofiles stubs. Can you reproduce with mypy master?

@julaudo
Copy link
Author

julaudo commented Nov 25, 2020

In particular, typeshed has since made improvements to the aiofiles stubs. Can you reproduce with mypy master?

You're right, mypy master does not report errors. I will be able to close the issue at next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants