Repository: psf/black

Issue:
In Python 3.9, it doesn't seem to pass the mypy check in pre-commit
**Describe the bug** According to the CONTRIBUTING.md,

>Development on the latest version of Python is preferred.  As of this writing it's 3.9.

But I ran the `pre-commit run -a` command and I was faced with mypy errors.

```
$ pre-commit run -a
black....................................................................Passed
flake8...................................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 2

src/black_primer/lib.py:37:12: error: syntax error in type comment
src/black_primer/lib.py:38:22: error: syntax error in type comment
src/black_primer/lib.py:42:10: error: syntax error in type comment
src/black_primer/lib.py:44:10: error: syntax error in type comment
src/black_primer/lib.py:45:10: error: syntax error in type comment
src/black_primer/lib.py:46:6: error: syntax error in type comment
src/black_primer/lib.py:111:38: error: syntax error in type comment
src/black_primer/lib.py:155:21: error: syntax error in type comment
src/black_primer/lib.py:159:6: error: syntax error in type comment
src/black_primer/lib.py:188:38: error: syntax error in type comment
src/black_primer/lib.py:213:6: error: syntax error in type comment
src/black_primer/lib.py:230:13: error: syntax error in type comment
Found 12 errors in 1 file (checked 14 source files)

prettier.................................................................Passed
```

**To Reproduce** The following commands:

```
# At the root of this repository
python3.9 -m venv env
. env/bin/activate
pip install -U pip
pip install pipenv
pipenv install --dev
pipenv shell
pre-commit install
pre-commit run -a
# See the above mypy errors
```

**Expected behavior** no mypy errors.

**Environment:**

- Version: master (a522aa4)
- OS and Python version: macOS/Python 3.9.0
- mypy version

```
$ mypy --version
mypy 0.790
$ pipenv run mypy --version
mypy 0.790
```

**Does this bug also happen on master?** Yes

**Additional context** 
I think others who want to contribute Black will have trouble.
As a temporary workaround, no error occurs in using Python **3.8**.


Discussion:
AFAIK this was a bug in mypy version `0.770`: https://github.com/python/mypy/issues/8614

The lock file contains mypy version `0.790` yet our pre-commit configuration is still using mypy version `0.770`. There's an open [PR to update our pre-commit configuration to use mypy `0.790`](https://github.com/psf/black/pull/1849) but 1) it's in no state to be merged, and 2) there's a new error that doesn't seem easy to fix.

~/cc @cooperlees I would like to bump priority on getting that PR ready if possible!~

Nevermind, as a temporary workaround, I've submitted [a PR](https://github.com/psf/black/pull/1887) to bump mypy to `0.780` in our pre-commit configuration to unblock development on CPython 3.9.
Oh, and before I forget again, thank you @ftnext for letting us know of this issue! This is not a great situation to be in and without you we would have stayed in such situation for probably quite a while!

Resolving patch:
diff --git a/src/black_primer/lib.py b/src/black_primer/lib.py
--- a/src/black_primer/lib.py
+++ b/src/black_primer/lib.py
@@ -58,13 +58,16 @@ async def _gen_check_output(
         await process.wait()
         raise
 
-    if process.returncode != 0:
-        returncode = process.returncode
-        if returncode is None:
-            returncode = 69
+    # A non-optional timeout was supplied to asyncio.wait_for, guaranteeing
+    # a timeout or completed process.  A terminated Python process will have a
+    # non-empty returncode value.
+    assert process.returncode is not None
 
+    if process.returncode != 0:
         cmd_str = " ".join(cmd)
-        raise CalledProcessError(returncode, cmd_str, output=stdout, stderr=stderr)
+        raise CalledProcessError(
+            process.returncode, cmd_str, output=stdout, stderr=stderr
+        )
 
     return (stdout, stderr)
 


Test patch: