]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
chore: ignore type error reported by mypy 1.12, 1.13
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 30 Oct 2024 13:26:34 +0000 (14:26 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 30 Oct 2024 13:58:40 +0000 (14:58 +0100)
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

psycopg/psycopg/waiting.py

index 0a808346ef81795374d28be476269adc974ca07b..420234df9c5d9bb9d05d0505fb1c23a5e454e597 100644 (file)
@@ -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