-
Notifications
You must be signed in to change notification settings - Fork 102
Closed
Description
I'm using apsw from pypi (thanks for that!)
I found some issues with the type stubs.
Some valid code that fails type-checking:
import apsw
conn = apsw.Connection(":memory:")
cur = conn.cursor()
cur.execute("CREATE TABLE t (x INT PRIMARY KEY)")
cur.execute("SELECT * FROM t")
for row in cur:
pass
row = cur.execute("SELECT * FROM t").fetchone()$ pip freeze | grep -E '(mypy|apsw)=='
apsw==3.38.5.post1
mypy==0.961
$ mypy test.py
test.py:6: error: "Cursor" has no attribute "__iter__" (not iterable)
test.py:8: error: "Iterator[Any]" has no attribute "fetchone"
Found 2 errors in 1 file (checked 1 source file)
Cursor.execute()returnsIterator- It should return
Cursor. (Actually it should returntyping.Self, but that's new in 3.11 beta, and there isn't a nice way to declare this in a backwards-compatible way yet)
- It should return
Cursordoesn't expose__iter__()/__next__()in type stubs.- The iterator protocol methods should be exposed in the type stubs, as well as any other methods that are part of the public API.
Cursor.__iter__()should returnCursor(orSelf)Cursor.__next__()should returnAny, or perhaps a narrower row type (IMO the row type should be narrower thanAny, but I'll file a separate issue about this)
Metadata
Metadata
Assignees
Labels
No labels