From: Daniele Varrazzo Date: Wed, 30 Oct 2024 13:26:34 +0000 (+0100) Subject: chore: ignore type error reported by mypy 1.12, 1.13 X-Git-Tag: 3.2.4~33 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=50ec089e69f28920676b93b72be0548950aa5360;p=thirdparty%2Fpsycopg.git chore: ignore type error reported by mypy 1.12, 1.13 If a generator returns None, the StopIteration.args tuple is empty. The fact we explicitly checks for it and in that case we return none looks now an error for Mypy. I don't see an obvious way around it. Maybe related to https://github.com/python/mypy/issues/1933 which is an historical issue (opened in 2016). Reported in https://github.com/python/mypy/issues/18073 --- diff --git a/psycopg/psycopg/waiting.py b/psycopg/psycopg/waiting.py index 0a808346e..420234df9 100644 --- a/psycopg/psycopg/waiting.py +++ b/psycopg/psycopg/waiting.py @@ -64,7 +64,8 @@ def wait_selector(gen: PQGen[RV], fileno: int, interval: float | None = None) -> sel.register(fileno, s) except StopIteration as ex: - rv: RV = ex.args[0] if ex.args else None + # https://github.com/python/mypy/issues/18073 + rv: RV = ex.args[0] if ex.args else None # type: ignore[assignment] return rv @@ -99,7 +100,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 + rv: RV = ex.args[0] if ex.args else None # type: ignore[assignment] return rv @@ -160,7 +161,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 + rv: RV = ex.args[0] if ex.args else None # type: ignore[assignment] return rv @@ -218,7 +219,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 + rv: RV = ex.args[0] if ex.args else None # type: ignore[assignment] return rv @@ -255,7 +256,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 + rv: RV = ex.args[0] if ex.args else None # type: ignore[assignment] return rv @@ -311,7 +312,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 + rv: RV = ex.args[0] if ex.args else None # type: ignore[assignment] return rv @@ -359,7 +360,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 + rv: RV = ex.args[0] if ex.args else None # type: ignore[assignment] return rv