]> 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>
Thu, 14 Nov 2024 09:28:53 +0000 (10:28 +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 4f307b6ef38693235b542cd9d8c84fb636de732a..5fee69577f15fe458e90d3246134e68a12c30208 100644 (file)
@@ -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