Problem
cursors using the RealDictCursor cursor factory are being caught as untyped in mypy strict mode.
Versions
mypy==1.17.0
psycopg2==2.9.10
types-psycopg2==2.9.21.20250516
Issue not present in types-psycopg2==2.9.21.20250318 and still "reveals" as Any
Replication
Save the below script
import psycopg2
from psycopg2.extras import RealDictCursor
def main(conn: psycopg2.extensions.connection) -> None:
with conn.cursor(cursor_factory=RealDictCursor) as cursor:
reveal_type(cursor.execute("SELECT * FROM users"))
run mypy --strict
↳ mypy --strict .
main.py:7: error: Call to untyped function "execute" in typed context [no-untyped-call]
main.py:7: note: Revealed type is "Any"
Found 1 error in 1 file (checked 1 source file)