]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Make spiketest.py script mypy-clean
authorDenis Laxalde <denis.laxalde@dalibo.com>
Tue, 2 Nov 2021 14:19:57 +0000 (15:19 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 3 Nov 2021 15:56:06 +0000 (16:56 +0100)
- allow untyped defs/calls (as everywhere else in tests/*)
- avoid list comprehension filled with no value
- add a type variable to Connection subclass
- drop useless sys.exit() call, since main() does not return a value

tests/scripts/spiketest.py

index e26d91bf751bcb928c931afe0e7ec06cf2f32906..6de342970a44fc8b63c46263859d96e2224781c7 100644 (file)
@@ -8,18 +8,20 @@ The test is inspired to the `spike analysis`__ illustrated by HikariCP
        Welcome-To-The-Jungle.md
 
 """
+# mypy: allow-untyped-defs
+# mypy: allow-untyped-calls
 
-import sys
 import time
 import threading
 
 import psycopg
 import psycopg_pool
+from psycopg.rows import Row
 
 import logging
 
 
-def main():
+def main() -> None:
     opt = parse_cmdline()
     if opt.loglevel:
         loglevel = getattr(logging, opt.loglevel.upper())
@@ -47,7 +49,8 @@ def main():
             )
             for i in range(opt.num_clients)
         ]
-        [t.start() for t in threads]
+        for t in threads:
+            t.start()
         time.sleep(0.2)
 
         # Release the threads!
@@ -56,7 +59,8 @@ def main():
         ev.set()
 
         # Wait for the threads to finish
-        [t.join() for t in threads]
+        for t in threads:
+            t.join()
         t1 = time.time()
         measurer.stop()
 
@@ -103,7 +107,7 @@ class Measurer:
             time.sleep(interval)
 
 
-class DelayedConnection(psycopg.Connection):
+class DelayedConnection(psycopg.Connection[Row]):
     """A connection adding a delay to the connection time."""
 
     @classmethod
@@ -155,4 +159,4 @@ def parse_cmdline():
 
 
 if __name__ == "__main__":
-    sys.exit(main())
+    main()