types-psycopg2 2.9.12 contains this commit:
which removes Any as the return type of the last variant, allowing
mypy to type-check the returned value.
However, mypy 0.920 only considers the last variant, even though we use
the first one; causing the return type to be badly inferred, and
erroring every time we use it as context manager.