Mypy should report errors when bpo-33346 would occur
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
https://bugs.python.org/issue33346 details some cases where you would get
SyntaxError: asynchronous comprehension outside of an asynchronous function
in some versions of Python, but mypy doesn't complain about these cases. Arguably this isn't necessarily specific to type checking, but it would be nice to report an error if Python is going to give a syntax error (even though it parses!)
I'm not quite sure what version of Python the fix (https://github.com/python/cpython/commit/054e9c84ac7c394941bba3ea1829d14dce1243fc) is in, but it would be nice to give an error message like "await cannot be used in dict comprehensions" in older versions of Python - especially because the error Python gives at runtime is not so good and doesn't include a line number, which gives a subpar experience trying to fix it - something mypy could provide a solution for.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading bpo-33346 and the referenced CPython commit to identify the asynchronous-comprehension cases and affected Python versions. Then trace how mypy handles these constructs and its version-specific diagnostics; done means older-version targets report the invalid await usage with a useful line number.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100