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: pool-3.2.4~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=53009a7660cd4184ad5309ce5270ffa6bd9ad28b;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 4f307b6ef..5fee69577 100644 --- a/psycopg/psycopg/waiting.py +++ b/psycopg/psycopg/waiting.py @@ -65,7 +65,8 @@ def wait_selector(gen: PQGen[RV], fileno: int, timeout: Optional[float] = 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 @@ -98,7 +99,7 @@ def wait_conn(gen: PQGenConn[RV], timeout: Optional[float] = None) -> RV: 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 @@ -161,7 +162,7 @@ async def wait_async( # 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 @@ -219,7 +220,7 @@ async def wait_conn_async(gen: PQGenConn[RV], timeout: Optional[float] = None) - raise e.ConnectionTimeout("connection timeout expired") 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 @@ -256,7 +257,7 @@ def wait_select(gen: PQGen[RV], fileno: int, timeout: Optional[float] = None) -> 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 @@ -312,7 +313,7 @@ def wait_epoll(gen: PQGen[RV], fileno: int, timeout: Optional[float] = None) -> 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 @@ -360,7 +361,7 @@ def wait_poll(gen: PQGen[RV], fileno: int, timeout: Optional[float] = None) -> R 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