prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 718 forks source link

Fix mypy configuration by ignoring two files, to satisfy CI #1710

Closed amotl closed 1 year ago

amotl commented 1 year ago

Hi again,

at GH-1709, we discovered that the test suite on CI currently croaks from an error with mypy. mypy raised this error on four occasions (see below):

error: "_SupportsAcloseT" has no attribute "__aiter__" (not async iterable)  [attr-defined]

This patch aims to silence this error by ignoring the corresponding files, in order to satisfy CI. Let us know if you think this should be made happen differently.

With kind regards, Andreas.


The root cause are those errors, where both https://github.com/python/mypy/issues/10301 and https://github.com/python/mypy/issues/5385#issuecomment-407281656 have interesting information, with a specific suggestion by @JelleZijlstra:

I think you shouldn't make the protocol function async def, but just def. Conceptually, an async generator is a callable that returns an AsyncIterator (or more precisely, an AsyncGenerator). But an async def function without a yield returns an Awaitable of whatever its declared return type is, so that's how mypy interprets your protocol.

$ mypy --strict src/prompt_toolkit --platform win32
src/prompt_toolkit/completion/base.py:284: error: "_SupportsAcloseT" has no attribute "__aiter__" (not async iterable)  [attr-defined]
src/prompt_toolkit/completion/base.py:367: error: "_SupportsAcloseT" has no attribute "__aiter__" (not async iterable)  [attr-defined]
src/prompt_toolkit/completion/base.py:395: error: "_SupportsAcloseT" has no attribute "__aiter__" (not async iterable)  [attr-defined]
src/prompt_toolkit/buffer.py:1763: error: "_SupportsAcloseT" has no attribute "__aiter__" (not async iterable)  [attr-defined]
jonathanslenders commented 1 year ago

Hi @amotl! Thanks for pointing out the issue.

I just had a look. No need to ignore anything. This should fix it instead: https://github.com/prompt-toolkit/python-prompt-toolkit/pull/1711

amotl commented 1 year ago

Lovely. Thanks for fixing it in a correct way so quickly.