python / python/mypy

Mypy should report errors when bpo-33346 would occur

Open
#14,256 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-async
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.