]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Better naming and typing for a couple of vars
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 8 Jun 2021 12:58:59 +0000 (13:58 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 8 Jun 2021 16:09:51 +0000 (17:09 +0100)
Note that mypy has some issue there, so a "type: ignore" that seems
required cannot be actually added.

psycopg3/psycopg3/waiting.py

index 3db9954dbeb6f7a4288f2f3e9d56aad7c12f6412..f4a779cfe22484d95322ce49cbb31ccc0df1211c 100644 (file)
@@ -53,11 +53,13 @@ def wait_selector(
         sel = DefaultSelector()
         while 1:
             sel.register(fileno, s)
-            ready = None
-            while not ready:
-                ready = sel.select(timeout=timeout)
+            rlist = None
+            while not rlist:
+                rlist = sel.select(timeout=timeout)
             sel.unregister(fileno)
-            s = gen.send(ready[0][1])
+            # note: this line should require a cast, but mypy doesn't complain
+            ready: Ready = rlist[0][1]
+            s = gen.send(ready)
 
     except StopIteration as ex:
         rv: RV = ex.args[0] if ex.args else None
@@ -84,11 +86,12 @@ def wait_conn(gen: PQGenConn[RV], timeout: Optional[float] = None) -> RV:
         sel = DefaultSelector()
         while 1:
             sel.register(fileno, s)
-            ready = sel.select(timeout=timeout)
+            rlist = sel.select(timeout=timeout)
             sel.unregister(fileno)
-            if not ready:
+            if not rlist:
                 raise e.OperationalError("timeout expired")
-            fileno, s = gen.send(ready[0][1])  # type: ignore[arg-type]
+            ready: Ready = rlist[0][1]  # type: ignore[assignment]
+            fileno, s = gen.send(ready)
 
     except StopIteration as ex:
         rv: RV = ex.args[0] if ex.args else None