Steps to reproduce
- Create a new venv and install the relevant packages:
pip3 install mypy psycopg2 types-psycopg2
- Create a file
example.py containing from psycopg2 import cursor
- Typecheck this file with Mypy:
mypy example.py
This will result in the following error:
example.py:1: error: Module "psycopg2" does not explicitly export attribute "cursor" [attr-defined]
Suggested fix
Apparently, recent versions of Mypy need stub definitions to be explicitly exported via __all__, but this is missing from the psycopg2 stubs. So it's probably just to add those?