@@ -287,6 +287,33 @@ def test_int64(provider):
287287 res = cur .execute ("SELECT * FROM data" )
288288 assert [(1 , 1099511627776 )] == res .fetchall ()
289289
290+ def test_type_adherence (capsys ):
291+ try :
292+ from mypy .stubtest import test_stubs , parse_options
293+ except (ImportError , ModuleNotFoundError ):
294+ # skip test if mypy not installed
295+ pytest .skip ("Cant test type stubs without mypy installed" )
296+
297+ # run mypy stubtest tool. Equivalent to running the following the terminal
298+ """
299+ stubtest --concise libsql_experimental | \
300+ grep -v 'which is incompatible with stub argument type'
301+ """
302+ test_stubs (parse_options (["--concise" , "libsql_experimental" ]))
303+ cap = capsys .readouterr ()
304+
305+ # this is part of error reported if is default parameter is ellipsis
306+ # `arg: type = ...` which is a nicer way to hide implementation from user
307+ # than having the more "correct" `arg: type | None = None` everywhere
308+ ellipsis_err = "which is incompatible with stub argument type"
309+
310+ lines = cap .out .split ("\n " )
311+ lines = filter (lambda x : ellipsis_err not in x , lines ) # filter false positives from ellipsis
312+ lines = filter (lambda x : len (x ) != 0 , lines ) # filter empty lines
313+
314+ # there will always be one error which i dont know how to get rid of
315+ # `libsql_experimental.libsql_experimental failed to find stubs`
316+ assert len (list (lines )) == 1
290317
291318def connect (provider , database , isolation_level = "DEFERRED" , autocommit = - 1 ):
292319 if provider == "libsql-remote" :
0 commit comments