From: Daniele Varrazzo Date: Wed, 30 Oct 2024 16:41:49 +0000 (+0100) Subject: refactor: use StopIteration.value instead of args as return after waiting X-Git-Tag: 3.2.4~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=677e33ff4a7136e19051c033951d8a7e1ab861e0;p=thirdparty%2Fpsycopg.git refactor: use StopIteration.value instead of args as return after waiting Work around the issue reported in https://github.com/python/mypy/issues/18073 Thank you very much, @brianschubert, for pointing it out! --- diff --git a/psycopg/psycopg/waiting.py b/psycopg/psycopg/waiting.py index 420234df9..449918679 100644 --- a/psycopg/psycopg/waiting.py +++ b/psycopg/psycopg/waiting.py @@ -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 diff --git a/psycopg_c/psycopg_c/_psycopg/waiting.pyx b/psycopg_c/psycopg_c/_psycopg/waiting.pyx index 6b22baf2c..ed04bb472 100644 --- a/psycopg_c/psycopg_c/_psycopg/waiting.pyx +++ b/psycopg_c/psycopg_c/_psycopg/waiting.pyx @@ -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