]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor: use StopIteration.value instead of args as return after waiting
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 30 Oct 2024 16:41:49 +0000 (17:41 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 30 Oct 2024 16:41:49 +0000 (17:41 +0100)
Work around the issue reported in https://github.com/python/mypy/issues/18073

Thank you very much, @brianschubert, for pointing it out!

psycopg/psycopg/waiting.py
psycopg_c/psycopg_c/_psycopg/waiting.pyx

index 420234df9c5d9bb9d05d0505fb1c23a5e454e597..4499186793faa6a1e09bab7d76b97fdfa3fb3755 100644 (file)
@@ -64,8 +64,7 @@ def wait_selector(gen: PQGen[RV], fileno: int, interval: float | None = None) ->
                 sel.register(fileno, s)
 
     except StopIteration as ex:
-        # https://github.com/python/mypy/issues/18073
-        rv: RV = ex.args[0] if ex.args else None  # type: ignore[assignment]
+        rv: RV = ex.value
         return rv
 
 
@@ -100,7 +99,7 @@ def wait_conn(gen: PQGenConn[RV], interval: float | None = None) -> RV:
                 sel.register(fileno, s)
 
     except StopIteration as ex:
-        rv: RV = ex.args[0] if ex.args else None  # type: ignore[assignment]
+        rv: RV = ex.value
         return rv
 
 
@@ -161,7 +160,7 @@ async def wait_async(gen: PQGen[RV], fileno: int, interval: float | None = None)
         # Assume the connection was closed
         raise e.OperationalError(str(ex))
     except StopIteration as ex:
-        rv: RV = ex.args[0] if ex.args else None  # type: ignore[assignment]
+        rv: RV = ex.value
         return rv
 
 
@@ -219,7 +218,7 @@ async def wait_conn_async(gen: PQGenConn[RV], interval: float | None = None) ->
             fileno, s = gen.send(ready)
 
     except StopIteration as ex:
-        rv: RV = ex.args[0] if ex.args else None  # type: ignore[assignment]
+        rv: RV = ex.value
         return rv
 
 
@@ -256,7 +255,7 @@ def wait_select(gen: PQGen[RV], fileno: int, interval: float | None = None) -> R
             s = gen.send(ready)
 
     except StopIteration as ex:
-        rv: RV = ex.args[0] if ex.args else None  # type: ignore[assignment]
+        rv: RV = ex.value
         return rv
 
 
@@ -312,7 +311,7 @@ def wait_epoll(gen: PQGen[RV], fileno: int, interval: float | None = None) -> RV
                 epoll.modify(fileno, evmask)
 
     except StopIteration as ex:
-        rv: RV = ex.args[0] if ex.args else None  # type: ignore[assignment]
+        rv: RV = ex.value
         return rv
 
 
@@ -360,7 +359,7 @@ def wait_poll(gen: PQGen[RV], fileno: int, interval: float | None = None) -> RV:
             poll.modify(fileno, evmask)
 
     except StopIteration as ex:
-        rv: RV = ex.args[0] if ex.args else None  # type: ignore[assignment]
+        rv: RV = ex.value
         return rv
 
 
index 6b22baf2cb57cf149f55de3a57e2081e06aa945d..ed04bb47215468162e4efea9237f5339b9631772 100644 (file)
@@ -213,5 +213,5 @@ def wait_c(gen: PQGen[RV], int fileno, interval = None) -> RV:
             wait = PyObject_CallFunctionObjArgs(send, pyready, NULL)
 
     except StopIteration as ex:
-        rv: RV = ex.args[0] if ex.args else None
+        rv: RV = ex.value
         return rv