]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Ignore mypy errors about cursor.fetchone()
authorDenis Laxalde <denis.laxalde@dalibo.com>
Tue, 2 Nov 2021 13:44:38 +0000 (14:44 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 3 Nov 2021 15:55:14 +0000 (16:55 +0100)
fetchone() can return None, so mypy complains that '"None" object is
not iterable' (or not indexable).

tests/pool/test_pool.py
tests/pool/test_pool_async.py

index fc30c973042036bf32606b956313739ed737918a..22353d750aa1579ca53a4bf90692a9a02b446b09 100644 (file)
@@ -73,11 +73,11 @@ def test_its_really_a_pool(dsn):
     with pool.ConnectionPool(dsn, min_size=2) as p:
         with p.connection() as conn:
             with conn.execute("select pg_backend_pid()") as cur:
-                (pid1,) = cur.fetchone()
+                (pid1,) = cur.fetchone()  # type: ignore[misc]
 
             with p.connection() as conn2:
                 with conn2.execute("select pg_backend_pid()") as cur:
-                    (pid2,) = cur.fetchone()
+                    (pid2,) = cur.fetchone()  # type: ignore[misc]
 
         with p.connection() as conn:
             assert conn.pgconn.backend_pid in (pid1, pid2)
@@ -172,18 +172,18 @@ def test_configure(dsn):
         with p.connection() as conn:
             assert inits == 1
             res = conn.execute("show default_transaction_read_only")
-            assert res.fetchone()[0] == "on"
+            assert res.fetchone()[0] == "on"  # type: ignore[index]
 
         with p.connection() as conn:
             assert inits == 1
             res = conn.execute("show default_transaction_read_only")
-            assert res.fetchone()[0] == "on"
+            assert res.fetchone()[0] == "on"  # type: ignore[index]
             conn.close()
 
         with p.connection() as conn:
             assert inits == 2
             res = conn.execute("show default_transaction_read_only")
-            assert res.fetchone()[0] == "on"
+            assert res.fetchone()[0] == "on"  # type: ignore[index]
 
 
 @pytest.mark.slow
@@ -295,7 +295,7 @@ def test_queue(dsn, retries):
         with p.connection() as conn:
             (pid,) = conn.execute(
                 "select pg_backend_pid() from pg_sleep(0.2)"
-            ).fetchone()
+            ).fetchone()  # type: ignore[misc]
         t1 = time()
         results.append((n, t1 - t0, pid))
 
@@ -362,7 +362,7 @@ def test_queue_timeout(dsn, retries):
         t0 = time()
         try:
             with p.connection() as conn:
-                (pid,) = conn.execute(
+                (pid,) = conn.execute(  # type: ignore[misc]
                     "select pg_backend_pid() from pg_sleep(0.2)"
                 ).fetchone()
         except pool.PoolTimeout as e:
@@ -426,7 +426,7 @@ def test_queue_timeout_override(dsn, retries):
         timeout = 0.25 if n == 3 else None
         try:
             with p.connection(timeout=timeout) as conn:
-                (pid,) = conn.execute(
+                (pid,) = conn.execute(  # type: ignore[misc]
                     "select pg_backend_pid() from pg_sleep(0.2)"
                 ).fetchone()
         except pool.PoolTimeout as e:
@@ -458,12 +458,12 @@ def test_broken_reconnect(dsn):
     with pool.ConnectionPool(dsn, min_size=1) as p:
         with p.connection() as conn:
             with conn.execute("select pg_backend_pid()") as cur:
-                (pid1,) = cur.fetchone()
+                (pid1,) = cur.fetchone()  # type: ignore[misc]
             conn.close()
 
         with p.connection() as conn2:
             with conn2.execute("select pg_backend_pid()") as cur:
-                (pid2,) = cur.fetchone()
+                (pid2,) = cur.fetchone()  # type: ignore[misc]
 
     assert pid1 != pid2
 
@@ -638,9 +638,8 @@ def test_closed_putconn(dsn):
 def test_closed_queue(dsn, retries):
     def w1():
         with p.connection() as conn:
-            assert (
-                conn.execute("select 1 from pg_sleep(0.2)").fetchone()[0] == 1
-            )
+            cur = conn.execute("select 1 from pg_sleep(0.2)")
+            assert cur.fetchone()[0] == 1  # type: ignore[index]
         success.append("w1")
 
     def w2():
index 94ce17fb928dffd5e0f1ab61a9da8e53e865c747..6bc68f25cc6e8617c05c5e226348736ea38b1af2 100644 (file)
@@ -71,11 +71,11 @@ async def test_its_really_a_pool(dsn):
     async with pool.AsyncConnectionPool(dsn, min_size=2) as p:
         async with p.connection() as conn:
             cur = await conn.execute("select pg_backend_pid()")
-            (pid1,) = await cur.fetchone()
+            (pid1,) = await cur.fetchone()  # type: ignore[misc]
 
             async with p.connection() as conn2:
                 cur = await conn2.execute("select pg_backend_pid()")
-                (pid2,) = await cur.fetchone()
+                (pid2,) = await cur.fetchone()  # type: ignore[misc]
 
         async with p.connection() as conn:
             assert conn.pgconn.backend_pid in (pid1, pid2)
@@ -178,18 +178,18 @@ async def test_configure(dsn):
         async with p.connection() as conn:
             assert inits == 1
             res = await conn.execute("show default_transaction_read_only")
-            assert (await res.fetchone())[0] == "on"
+            assert (await res.fetchone())[0] == "on"  # type: ignore[index]
 
         async with p.connection() as conn:
             assert inits == 1
             res = await conn.execute("show default_transaction_read_only")
-            assert (await res.fetchone())[0] == "on"
+            assert (await res.fetchone())[0] == "on"  # type: ignore[index]
             await conn.close()
 
         async with p.connection() as conn:
             assert inits == 2
             res = await conn.execute("show default_transaction_read_only")
-            assert (await res.fetchone())[0] == "on"
+            assert (await res.fetchone())[0] == "on"  # type: ignore[index]
 
 
 @pytest.mark.slow
@@ -306,7 +306,7 @@ async def test_queue(dsn, retries):
             cur = await conn.execute(
                 "select pg_backend_pid() from pg_sleep(0.2)"
             )
-            (pid,) = await cur.fetchone()
+            (pid,) = await cur.fetchone()  # type: ignore[misc]
         t1 = time()
         results.append((n, t1 - t0, pid))
 
@@ -369,7 +369,7 @@ async def test_queue_timeout(dsn, retries):
                 cur = await conn.execute(
                     "select pg_backend_pid() from pg_sleep(0.2)"
                 )
-                (pid,) = await cur.fetchone()
+                (pid,) = await cur.fetchone()  # type: ignore[misc]
         except pool.PoolTimeout as e:
             t1 = time()
             errors.append((n, t1 - t0, e))
@@ -430,7 +430,7 @@ async def test_queue_timeout_override(dsn, retries):
                 cur = await conn.execute(
                     "select pg_backend_pid() from pg_sleep(0.2)"
                 )
-                (pid,) = await cur.fetchone()
+                (pid,) = await cur.fetchone()  # type: ignore[misc]
         except pool.PoolTimeout as e:
             t1 = time()
             errors.append((n, t1 - t0, e))
@@ -459,12 +459,12 @@ async def test_broken_reconnect(dsn):
     async with pool.AsyncConnectionPool(dsn, min_size=1) as p:
         async with p.connection() as conn:
             cur = await conn.execute("select pg_backend_pid()")
-            (pid1,) = await cur.fetchone()
+            (pid1,) = await cur.fetchone()  # type: ignore[misc]
             await conn.close()
 
         async with p.connection() as conn2:
             cur = await conn2.execute("select pg_backend_pid()")
-            (pid2,) = await cur.fetchone()
+            (pid2,) = await cur.fetchone()  # type: ignore[misc]
 
     assert pid1 != pid2