From: Denis Laxalde Date: Tue, 2 Nov 2021 13:44:38 +0000 (+0100) Subject: Ignore mypy errors about cursor.fetchone() X-Git-Tag: 3.0.2~2^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e53ad34087a58129857e54d1757f479ce3996c46;p=thirdparty%2Fpsycopg.git Ignore mypy errors about cursor.fetchone() fetchone() can return None, so mypy complains that '"None" object is not iterable' (or not indexable). --- diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index fc30c9730..22353d750 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -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(): diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 94ce17fb9..6bc68f25c 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -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