Issue not present in types-psycopg2==2.9.21.20250318 and still "reveals" as Any
Replication
Save the below script
importpsycopg2frompsycopg2.extrasimportRealDictCursordefmain(conn: psycopg2.extensions.connection) ->None:
withconn.cursor(cursor_factory=RealDictCursor) ascursor:
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)
Yes, RealDictCursor.execute() is untyped in typeshed. We don't keep issues about untyped items open in typeshed, as this is a rather frequent and "expected" situation. That said, PRs that add or fix annotations are always welcome!
Understood. I only raised it as previously "ok" code is now not safely checking on the newer version, since whatever changed now surfaces an untyped func rather than a func returning Any.
Of course the Any is a "lie" too.
The issue was probably hidden before #14063 since vars was previously annotated as Incomplete | None = None, which made type checkers believe that execute was partly annotated (when it wasn't really).
Activity
srittau commented on Jul 16, 2025
Yes, RealDictCursor.execute() is untyped in typeshed. We don't keep issues about untyped items open in typeshed, as this is a rather frequent and "expected" situation. That said, PRs that add or fix annotations are always welcome!
Don-Burns commented on Jul 16, 2025
Understood. I only raised it as previously "ok" code is now not safely checking on the newer version, since whatever changed now surfaces an untyped func rather than a func returning Any.
Of course the Any is a "lie" too.
srittau commented on Jul 16, 2025
The issue was probably hidden before #14063 since vars was previously annotated as Incomplete | None = None, which made type checkers believe that execute was partly annotated (when it wasn't really).