]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
AsyncConnection.cursor() is no more async
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 10 Feb 2021 02:31:14 +0000 (03:31 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 10 Feb 2021 02:31:44 +0000 (03:31 +0100)
Even after implementing server-side cursors there is not really a reason
for it to be.

psycopg3/psycopg3/_typeinfo.py
psycopg3/psycopg3/connection.py
tests/test_concurrency_async.py
tests/test_connection_async.py
tests/test_copy_async.py
tests/test_cursor_async.py
tests/test_errors.py
tests/test_named_cursor_async.py
tests/test_prepared_async.py
tests/test_transaction.py
tests/test_transaction_async.py

index ce22aaffc0165efb56b44a8ad4d17a1c51ffabef..2d6fa245314d6fb02f5866220fcd747028833584 100644 (file)
@@ -88,7 +88,7 @@ class TypeInfo:
 
         if isinstance(name, Composable):
             name = name.as_string(conn)
-        cur = await conn.cursor(binary=True)
+        cur = conn.cursor(binary=True)
         await cur.execute(cls._info_query, {"name": name})
         recs = await cur.fetchall()
         fields = [d[0] for d in cur.description or ()]
index c2a5a8436715481177318db99fdb5a6fdf7e8dbd..0cc44d377e63e001853e4e041eef423254ebf185 100644 (file)
@@ -587,16 +587,14 @@ class AsyncConnection(BaseConnection):
         self.pgconn.finish()
 
     @overload
-    async def cursor(self, *, binary: bool = False) -> AsyncCursor:
+    def cursor(self, *, binary: bool = False) -> AsyncCursor:
         ...
 
     @overload
-    async def cursor(
-        self, name: str, *, binary: bool = False
-    ) -> AsyncNamedCursor:
+    def cursor(self, name: str, *, binary: bool = False) -> AsyncNamedCursor:
         ...
 
-    async def cursor(
+    def cursor(
         self, name: str = "", *, binary: bool = False
     ) -> Union[AsyncCursor, AsyncNamedCursor]:
         """
@@ -614,7 +612,7 @@ class AsyncConnection(BaseConnection):
         params: Optional[Params] = None,
         prepare: Optional[bool] = None,
     ) -> AsyncCursor:
-        cur = await self.cursor()
+        cur = self.cursor()
         return await cur.execute(query, params, prepare=prepare)
 
     async def commit(self) -> None:
index 02327e256bbcd5cff28b16cf8bef9e8c1c6ad7a5..6b21db1d373d3bb651527d70aa9a07f22fd633c8 100644 (file)
@@ -27,7 +27,7 @@ async def test_commit_concurrency(aconn):
 
     async def runner():
         nonlocal stop
-        cur = await aconn.cursor()
+        cur = aconn.cursor()
         for i in range(1000):
             await cur.execute("select %s;", (i,))
             await aconn.commit()
@@ -43,7 +43,7 @@ async def test_commit_concurrency(aconn):
 async def test_concurrent_execution(dsn):
     async def worker():
         cnn = await psycopg3.AsyncConnection.connect(dsn)
-        cur = await cnn.cursor()
+        cur = cnn.cursor()
         await cur.execute("select pg_sleep(0.5)")
         await cur.close()
         await cnn.close()
@@ -60,7 +60,7 @@ async def test_notifies(aconn, dsn):
     npid = nconn.pgconn.backend_pid
 
     async def notifier():
-        cur = await nconn.cursor()
+        cur = nconn.cursor()
         await asyncio.sleep(0.25)
         await cur.execute("notify foo, '1'")
         await asyncio.sleep(0.25)
@@ -69,7 +69,7 @@ async def test_notifies(aconn, dsn):
 
     async def receiver():
         await aconn.set_autocommit(True)
-        cur = await aconn.cursor()
+        cur = aconn.cursor()
         await cur.execute("listen foo")
         gen = aconn.notifies()
         async for n in gen:
@@ -109,7 +109,7 @@ async def test_cancel(aconn):
             errors.append(exc)
 
     async def worker():
-        cur = await aconn.cursor()
+        cur = aconn.cursor()
         with pytest.raises(psycopg3.DatabaseError):
             await cur.execute("select pg_sleep(2)")
 
@@ -124,6 +124,6 @@ async def test_cancel(aconn):
 
     # still working
     await aconn.rollback()
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("select 1")
     assert await cur.fetchone() == (1,)
index 71bfb6a1d0bfa1c858a8707cd347f0d40cbd71f9..8ba667b0180a95d878e5815d324c905d51501f54 100644 (file)
@@ -67,7 +67,7 @@ async def test_close(aconn):
     assert aconn.closed
     assert aconn.pgconn.status == aconn.ConnStatus.BAD
 
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
 
     await aconn.close()
     assert aconn.closed
@@ -108,33 +108,33 @@ async def test_connection_warn_close(dsn, recwarn):
 
 async def test_context_commit(aconn, dsn):
     async with aconn:
-        async with await aconn.cursor() as cur:
+        async with aconn.cursor() as cur:
             await cur.execute("drop table if exists textctx")
             await cur.execute("create table textctx ()")
 
     assert aconn.closed
 
     async with await psycopg3.AsyncConnection.connect(dsn) as aconn:
-        async with await aconn.cursor() as cur:
+        async with aconn.cursor() as cur:
             await cur.execute("select * from textctx")
             assert await cur.fetchall() == []
 
 
 async def test_context_rollback(aconn, dsn):
-    async with await aconn.cursor() as cur:
+    async with aconn.cursor() as cur:
         await cur.execute("drop table if exists textctx")
     await aconn.commit()
 
     with pytest.raises(ZeroDivisionError):
         async with aconn:
-            async with await aconn.cursor() as cur:
+            async with aconn.cursor() as cur:
                 await cur.execute("create table textctx ()")
                 1 / 0
 
     assert aconn.closed
 
     async with await psycopg3.AsyncConnection.connect(dsn) as aconn:
-        async with await aconn.cursor() as cur:
+        async with aconn.cursor() as cur:
             with pytest.raises(UndefinedTable):
                 await cur.execute("select * from textctx")
 
@@ -197,7 +197,7 @@ async def test_auto_transaction(aconn):
     aconn.pgconn.exec_(b"drop table if exists foo")
     aconn.pgconn.exec_(b"create table foo (id int primary key)")
 
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     assert aconn.pgconn.transaction_status == aconn.TransactionStatus.IDLE
 
     await cur.execute("insert into foo values (1)")
@@ -214,7 +214,7 @@ async def test_auto_transaction_fail(aconn):
     aconn.pgconn.exec_(b"drop table if exists foo")
     aconn.pgconn.exec_(b"create table foo (id int primary key)")
 
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     assert aconn.pgconn.transaction_status == aconn.TransactionStatus.IDLE
 
     await cur.execute("insert into foo values (1)")
@@ -239,7 +239,7 @@ async def test_autocommit(aconn):
 
     await aconn.set_autocommit(True)
     assert aconn.autocommit
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("select 1")
     assert await cur.fetchone() == (1,)
     assert aconn.pgconn.transaction_status == aconn.TransactionStatus.IDLE
@@ -251,7 +251,7 @@ async def test_autocommit_connect(dsn):
 
 
 async def test_autocommit_intrans(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("select 1")
     assert await cur.fetchone() == (1,)
     assert aconn.pgconn.transaction_status == aconn.TransactionStatus.INTRANS
@@ -261,7 +261,7 @@ async def test_autocommit_intrans(aconn):
 
 
 async def test_autocommit_inerror(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     with pytest.raises(psycopg3.DatabaseError):
         await cur.execute("meh")
     assert aconn.pgconn.transaction_status == aconn.TransactionStatus.INERROR
@@ -279,7 +279,7 @@ async def test_autocommit_unknown(aconn):
 
 
 async def test_get_encoding(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("show client_encoding")
     (enc,) = await cur.fetchone()
     assert aconn.client_encoding == encodings.pg2py(enc)
@@ -293,7 +293,7 @@ async def test_set_encoding(aconn):
     assert aconn.client_encoding != newenc
     await aconn.set_client_encoding(newenc)
     assert aconn.client_encoding == newenc
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("show client_encoding")
     (enc,) = await cur.fetchone()
     assert encodings.pg2py(enc) == newenc
@@ -340,7 +340,7 @@ async def test_encoding_env_var(dsn, monkeypatch, enc, out, codec):
 
 
 async def test_set_encoding_unsupported(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("set client_encoding to EUC_TW")
     with pytest.raises(psycopg3.NotSupportedError):
         await cur.execute("select 'x'")
@@ -399,7 +399,7 @@ async def test_connect_badargs(monkeypatch, pgconn, args, kwargs):
 
 
 async def test_broken_connection(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     with pytest.raises(psycopg3.DatabaseError):
         await cur.execute("select pg_terminate_backend(pg_backend_pid())")
     assert aconn.closed
@@ -422,7 +422,7 @@ async def test_notice_handlers(aconn, caplog):
     aconn.add_notice_handler(lambda diag: severities.append(diag.severity))
 
     aconn.pgconn.exec_(b"set client_min_messages to notice")
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute(
         "do $$begin raise notice 'hello notice'; end$$ language plpgsql"
     )
@@ -461,7 +461,7 @@ async def test_notify_handlers(aconn):
     aconn.add_notify_handler(lambda n: nots2.append(n))
 
     await aconn.set_autocommit(True)
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("listen foo")
     await cur.execute("notify foo, 'n1'")
 
index bf3a5ef905772ca9ad8c1f0d3abb605c016bb918..e679f79a0437d5d71ff7f2fe89cc31f861ce2612 100644 (file)
@@ -27,7 +27,7 @@ async def test_copy_out_read(aconn, format):
     else:
         want = sample_binary_rows
 
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy(
         f"copy ({sample_values}) to stdout (format {format.name})"
     ) as copy:
@@ -53,7 +53,7 @@ async def test_copy_out_iter(aconn, format):
     else:
         want = sample_binary_rows
 
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     got = []
     async with cur.copy(
         f"copy ({sample_values}) to stdout (format {format.name})"
@@ -67,7 +67,7 @@ async def test_copy_out_iter(aconn, format):
 
 @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY])
 async def test_read_rows(aconn, format):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy(
         f"copy ({sample_values}) to stdout (format {format.name})"
     ) as copy:
@@ -85,7 +85,7 @@ async def test_read_rows(aconn, format):
 
 @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY])
 async def test_rows(aconn, format):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy(
         f"copy ({sample_values}) to stdout (format {format.name})"
     ) as copy:
@@ -100,7 +100,7 @@ async def test_rows(aconn, format):
 
 @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY])
 async def test_copy_out_allchars(aconn, format):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     chars = list(map(chr, range(1, 256))) + [eur]
     await aconn.set_client_encoding("utf8")
     rows = []
@@ -121,7 +121,7 @@ async def test_copy_out_allchars(aconn, format):
 
 @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY])
 async def test_read_row_notypes(aconn, format):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy(
         f"copy ({sample_values}) to stdout (format {format.name})"
     ) as copy:
@@ -141,7 +141,7 @@ async def test_read_row_notypes(aconn, format):
 
 @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY])
 async def test_rows_notypes(aconn, format):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy(
         f"copy ({sample_values}) to stdout (format {format.name})"
     ) as copy:
@@ -158,7 +158,7 @@ async def test_rows_notypes(aconn, format):
 @pytest.mark.parametrize("err", [-1, 1])
 @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY])
 async def test_copy_out_badntypes(aconn, format, err):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy(
         f"copy ({sample_values}) to stdout (format {format.name})"
     ) as copy:
@@ -172,7 +172,7 @@ async def test_copy_out_badntypes(aconn, format, err):
     [(Format.TEXT, "sample_text"), (Format.BINARY, "sample_binary")],
 )
 async def test_copy_in_buffers(aconn, format, buffer):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
     async with cur.copy(
         f"copy copy_in from stdin (format {format.name})"
@@ -185,7 +185,7 @@ async def test_copy_in_buffers(aconn, format, buffer):
 
 
 async def test_copy_in_buffers_pg_error(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
     with pytest.raises(e.UniqueViolation):
         async with cur.copy("copy copy_in from stdin (format text)") as copy:
@@ -197,7 +197,7 @@ async def test_copy_in_buffers_pg_error(aconn):
 async def test_copy_bad_result(aconn):
     await aconn.set_autocommit(True)
 
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
 
     with pytest.raises(e.SyntaxError):
         async with cur.copy("wat"):
@@ -213,7 +213,7 @@ async def test_copy_bad_result(aconn):
 
 
 async def test_copy_in_str(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
     async with cur.copy("copy copy_in from stdin (format text)") as copy:
         await copy.write(sample_text.decode("utf8"))
@@ -224,7 +224,7 @@ async def test_copy_in_str(aconn):
 
 
 async def test_copy_in_str_binary(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
     with pytest.raises(e.QueryCanceled):
         async with cur.copy("copy copy_in from stdin (format binary)") as copy:
@@ -235,7 +235,7 @@ async def test_copy_in_str_binary(aconn):
 
 @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY])
 async def test_copy_in_empty(aconn, format):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
     async with cur.copy(f"copy copy_in from stdin (format {format.name})"):
         pass
@@ -246,7 +246,7 @@ async def test_copy_in_empty(aconn, format):
 
 @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY])
 async def test_copy_in_error_empty(aconn, format):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
     with pytest.raises(e.QueryCanceled) as exc:
         async with cur.copy(f"copy copy_in from stdin (format {format.name})"):
@@ -257,7 +257,7 @@ async def test_copy_in_error_empty(aconn, format):
 
 
 async def test_copy_in_buffers_with_pg_error(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
     with pytest.raises(e.UniqueViolation):
         async with cur.copy("copy copy_in from stdin (format text)") as copy:
@@ -268,7 +268,7 @@ async def test_copy_in_buffers_with_pg_error(aconn):
 
 
 async def test_copy_in_buffers_with_py_error(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
     with pytest.raises(e.QueryCanceled) as exc:
         async with cur.copy("copy copy_in from stdin (format text)") as copy:
@@ -281,7 +281,7 @@ async def test_copy_in_buffers_with_py_error(aconn):
 
 @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY])
 async def test_copy_in_records(aconn, format):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
 
     async with cur.copy(
@@ -297,7 +297,7 @@ async def test_copy_in_records(aconn, format):
 
 @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY])
 async def test_copy_in_records_binary(aconn, format):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, "col1 serial primary key, col2 int, data text")
 
     async with cur.copy(
@@ -312,7 +312,7 @@ async def test_copy_in_records_binary(aconn, format):
 
 
 async def test_copy_in_allchars(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
 
     await aconn.set_client_encoding("utf8")
@@ -336,7 +336,7 @@ async def test_copy_from_to(aconn):
     # Roundtrip from file to database to file blockwise
     gen = DataGenerator(aconn, nrecs=1024, srec=10 * 1024)
     await gen.ensure_table()
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy("copy copy_in from stdin") as copy:
         for block in gen.blocks():
             await copy.write(block)
@@ -357,7 +357,7 @@ async def test_copy_from_to_bytes(aconn):
     # Roundtrip from file to database to file blockwise
     gen = DataGenerator(aconn, nrecs=1024, srec=10 * 1024)
     await gen.ensure_table()
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy("copy copy_in from stdin") as copy:
         for block in gen.blocks():
             await copy.write(block.encode("utf8"))
@@ -380,7 +380,7 @@ async def test_copy_from_insane_size(aconn):
         aconn, nrecs=4 * 1024, srec=10 * 1024, block_size=20 * 1024 * 1024
     )
     await gen.ensure_table()
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy("copy copy_in from stdin") as copy:
         for block in gen.blocks():
             await copy.write(block)
@@ -392,7 +392,7 @@ async def test_copy_rowcount(aconn):
     gen = DataGenerator(aconn, nrecs=3, srec=10)
     await gen.ensure_table()
 
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy("copy copy_in from stdin") as copy:
         for block in gen.blocks():
             await copy.write(block)
@@ -417,7 +417,7 @@ async def test_copy_rowcount(aconn):
 
 
 async def test_copy_query(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy("copy (select 1) to stdout") as copy:
         assert cur.query == b"copy (select 1) to stdout"
         assert cur.params is None
@@ -426,7 +426,7 @@ async def test_copy_query(aconn):
 
 
 async def test_cant_reenter(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy("copy (select 1) to stdout") as copy:
         async for record in copy:
             pass
@@ -438,7 +438,7 @@ async def test_cant_reenter(aconn):
 
 
 async def test_str(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     async with cur.copy("copy (select 1) to stdout") as copy:
         assert "[ACTIVE]" in str(copy)
         async for record in copy:
@@ -452,7 +452,7 @@ async def test_str(aconn):
     [(Format.TEXT, "sample_text"), (Format.BINARY, "sample_binary")],
 )
 async def test_worker_life(aconn, format, buffer):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await ensure_table(cur, sample_tabledef)
     async with cur.copy(
         f"copy copy_in from stdin (format {format.name})"
@@ -478,7 +478,7 @@ async def test_copy_to_leaks(dsn, faker, fmt, method):
     n = []
     for i in range(3):
         async with await psycopg3.AsyncConnection.connect(dsn) as conn:
-            async with await conn.cursor(binary=fmt) as cur:
+            async with conn.cursor(binary=fmt) as cur:
                 await cur.execute(faker.drop_stmt)
                 await cur.execute(faker.create_stmt)
                 await cur.executemany(faker.insert_stmt, faker.records)
@@ -537,7 +537,7 @@ async def test_copy_from_leaks(dsn, faker, fmt):
     n = []
     for i in range(3):
         async with await psycopg3.AsyncConnection.connect(dsn) as conn:
-            async with await conn.cursor(binary=fmt) as cur:
+            async with conn.cursor(binary=fmt) as cur:
                 await cur.execute(faker.drop_stmt)
                 await cur.execute(faker.create_stmt)
 
@@ -582,7 +582,7 @@ class DataGenerator:
         self.block_size = block_size
 
     async def ensure_table(self):
-        cur = await self.conn.cursor()
+        cur = self.conn.cursor()
         await ensure_table(cur, "id integer primary key, data text")
 
     def records(self):
@@ -607,7 +607,7 @@ class DataGenerator:
             yield block
 
     async def assert_data(self):
-        cur = await self.conn.cursor()
+        cur = self.conn.cursor()
         await cur.execute("select id, data from copy_in order by id")
         for record in self.records():
             assert record == await cur.fetchone()
index c2344e16b3e4409c8076b805380213297238406a..4aeb396665d0fa82f4da0650e759f086e9b9900e 100644 (file)
@@ -11,7 +11,7 @@ pytestmark = pytest.mark.asyncio
 
 
 async def test_close(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     assert not cur.closed
     await cur.close()
     assert cur.closed
@@ -24,14 +24,14 @@ async def test_close(aconn):
 
 
 async def test_context(aconn):
-    async with (await aconn.cursor()) as cur:
+    async with aconn.cursor() as cur:
         assert not cur.closed
 
     assert cur.closed
 
 
 async def test_weakref(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     w = weakref.ref(cur)
     await cur.close()
     del cur
@@ -40,7 +40,7 @@ async def test_weakref(aconn):
 
 
 async def test_status(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     assert cur.status is None
     await cur.execute("reset all")
     assert cur.status == cur.ExecStatus.COMMAND_OK
@@ -51,7 +51,7 @@ async def test_status(aconn):
 
 
 async def test_execute_many_results(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     assert cur.nextset() is None
 
     rv = await cur.execute("select 'foo'; select generate_series(1,3)")
@@ -68,7 +68,7 @@ async def test_execute_many_results(aconn):
 
 
 async def test_execute_sequence(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     rv = await cur.execute(
         "select %s::int, %s::text, %s::text", [1, "foo", None]
     )
@@ -82,7 +82,7 @@ async def test_execute_sequence(aconn):
 
 @pytest.mark.parametrize("query", ["", " ", ";"])
 async def test_execute_empty_query(aconn, query):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute(query)
     assert cur.status == cur.ExecStatus.EMPTY_QUERY
     with pytest.raises(psycopg3.ProgrammingError):
@@ -93,14 +93,14 @@ async def test_execute_empty_query(aconn, query):
     "query", ["copy testcopy from stdin", "copy testcopy to stdout"]
 )
 async def test_execute_copy(aconn, query):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("create table testcopy (id int)")
     with pytest.raises(psycopg3.ProgrammingError):
         await cur.execute(query)
 
 
 async def test_fetchone(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("select %s::int, %s::text, %s::text", [1, "foo", None])
     assert cur.pgresult.fformat(0) == 0
 
@@ -113,7 +113,7 @@ async def test_fetchone(aconn):
 
 
 async def test_execute_binary_result(aconn):
-    cur = await aconn.cursor(binary=True)
+    cur = aconn.cursor(binary=True)
     await cur.execute("select %s::text, %s::text", ["foo", None])
     assert cur.pgresult.fformat(0) == 1
 
@@ -127,7 +127,7 @@ async def test_execute_binary_result(aconn):
 @pytest.mark.parametrize("encoding", ["utf8", "latin9"])
 async def test_query_encode(aconn, encoding):
     await aconn.set_client_encoding(encoding)
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("select '\u20ac'")
     (res,) = await cur.fetchone()
     assert res == "\u20ac"
@@ -135,7 +135,7 @@ async def test_query_encode(aconn, encoding):
 
 async def test_query_badenc(aconn):
     await aconn.set_client_encoding("latin1")
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     with pytest.raises(UnicodeEncodeError):
         await cur.execute("select '\u20ac'")
 
@@ -152,7 +152,7 @@ async def execmany(svcconn):
 
 
 async def test_executemany(aconn, execmany):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.executemany(
         "insert into execmany(num, data) values (%s, %s)",
         [(10, "hello"), (20, "world")],
@@ -163,7 +163,7 @@ async def test_executemany(aconn, execmany):
 
 
 async def test_executemany_name(aconn, execmany):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.executemany(
         "insert into execmany(num, data) values (%(num)s, %(data)s)",
         [{"num": 11, "data": "hello", "x": 1}, {"num": 21, "data": "world"}],
@@ -174,7 +174,7 @@ async def test_executemany_name(aconn, execmany):
 
 
 async def test_executemany_rowcount(aconn, execmany):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.executemany(
         "insert into execmany(num, data) values (%s, %s)",
         [(10, "hello"), (20, "world")],
@@ -183,7 +183,7 @@ async def test_executemany_rowcount(aconn, execmany):
 
 
 async def test_executemany_returning_rowcount(aconn, execmany):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.executemany(
         "insert into execmany(num, data) values (%s, %s) returning num",
         [(10, "hello"), (20, "world")],
@@ -200,14 +200,14 @@ async def test_executemany_returning_rowcount(aconn, execmany):
     ],
 )
 async def test_executemany_badquery(aconn, query):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     with pytest.raises(psycopg3.DatabaseError):
         await cur.executemany(query, [(10, "hello"), (20, "world")])
 
 
 @pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
 async def test_executemany_null_first(aconn, fmt_in):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("create table testmany (a bigint, b bigint)")
     await cur.executemany(
         f"insert into testmany values (%{fmt_in}, %{fmt_in})",
@@ -221,7 +221,7 @@ async def test_executemany_null_first(aconn, fmt_in):
 
 
 async def test_rowcount(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
 
     await cur.execute("select 1 from generate_series(1, 0)")
     assert cur.rowcount == 0
@@ -244,7 +244,7 @@ async def test_rowcount(aconn):
 
 
 async def test_rownumber(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     assert cur.rownumber is None
 
     await cur.execute("select 1 from generate_series(1, 42)")
@@ -267,7 +267,7 @@ async def test_rownumber(aconn):
 
 
 async def test_iter(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("select generate_series(1, 3)")
     res = []
     async for rec in cur:
@@ -276,7 +276,7 @@ async def test_iter(aconn):
 
 
 async def test_iter_stop(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("select generate_series(1, 3)")
     async for rec in cur:
         assert rec == (1,)
@@ -292,7 +292,7 @@ async def test_iter_stop(aconn):
 
 
 async def test_scroll(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     with pytest.raises(psycopg3.ProgrammingError):
         await cur.scroll(0)
 
@@ -334,7 +334,7 @@ async def test_scroll(aconn):
 
 
 async def test_query_params_execute(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     assert cur.query is None
     assert cur.params is None
 
@@ -354,7 +354,7 @@ async def test_query_params_execute(aconn):
 
 
 async def test_query_params_executemany(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
 
     await cur.executemany("select %t, %t", [[1, 2], [3, 4]])
     assert cur.query == b"select $1, $2"
@@ -369,7 +369,7 @@ async def test_query_params_executemany(aconn):
 
 
 async def test_stream(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     recs = []
     async for rec in cur.stream(
         "select i, '2021-01-01'::date + i from generate_series(1, %s) as i",
@@ -381,7 +381,7 @@ async def test_stream(aconn):
 
 
 async def test_stream_sql(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     recs = []
     async for rec in cur.stream(
         sql.SQL(
@@ -402,14 +402,14 @@ async def test_stream_sql(aconn):
     ],
 )
 async def test_stream_badquery(aconn, query):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     with pytest.raises(psycopg3.ProgrammingError):
         async for rec in cur.stream(query):
             pass
 
 
 async def test_str(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     assert "[IDLE]" in str(cur)
     assert "[closed]" not in str(cur)
     assert "[no result]" in str(cur)
@@ -434,7 +434,7 @@ async def test_leak(dsn, faker, fmt, fetch):
     n = []
     for i in range(3):
         async with await psycopg3.AsyncConnection.connect(dsn) as conn:
-            async with await conn.cursor(binary=Format.as_pq(fmt)) as cur:
+            async with conn.cursor(binary=Format.as_pq(fmt)) as cur:
                 await cur.execute(faker.drop_stmt)
                 await cur.execute(faker.create_stmt)
                 await cur.executemany(faker.insert_stmt, faker.records)
index 07f81b99d91446b9c9858583916d24f798c6d4e0..663d1132de10d15d9e0032df2ec6fdee2bf8e1f2 100644 (file)
@@ -201,7 +201,7 @@ def test_diag_from_commit(conn):
 
 @pytest.mark.asyncio
 async def test_diag_from_commit_async(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute(
         """
         create temp table test_deferred (
index 0ae150229d1ead8059b980ae13e34fec58ac51d6..7d6fa49b1a12885dadb71db051a315c5a12e9c84 100644 (file)
@@ -4,14 +4,14 @@ pytestmark = pytest.mark.asyncio
 
 
 async def test_funny_name(aconn):
-    cur = await aconn.cursor("1-2-3")
+    cur = aconn.cursor("1-2-3")
     await cur.execute("select generate_series(1, 3) as bar")
     assert await cur.fetchall() == [(1,), (2,), (3,)]
     assert cur.name == "1-2-3"
 
 
 async def test_description(aconn):
-    cur = await aconn.cursor("foo")
+    cur = aconn.cursor("foo")
     assert cur.name == "foo"
     await cur.execute("select generate_series(1, 10) as bar")
     assert len(cur.description) == 1
@@ -21,7 +21,7 @@ async def test_description(aconn):
 
 
 async def test_close(aconn, recwarn):
-    cur = await aconn.cursor("foo")
+    cur = aconn.cursor("foo")
     await cur.execute("select generate_series(1, 10) as bar")
     await cur.close()
     assert cur.closed
@@ -34,13 +34,13 @@ async def test_close(aconn, recwarn):
 
 
 async def test_close_noop(aconn, recwarn):
-    cur = await aconn.cursor("foo")
+    cur = aconn.cursor("foo")
     await cur.close()
     assert not recwarn
 
 
 async def test_context(aconn, recwarn):
-    async with await aconn.cursor("foo") as cur:
+    async with aconn.cursor("foo") as cur:
         await cur.execute("select generate_series(1, 10) as bar")
 
     assert cur.closed
@@ -52,14 +52,14 @@ async def test_context(aconn, recwarn):
 
 
 async def test_warn_close(aconn, recwarn):
-    cur = await aconn.cursor("foo")
+    cur = aconn.cursor("foo")
     await cur.execute("select generate_series(1, 10) as bar")
     del cur
     assert ".close()" in str(recwarn.pop(ResourceWarning).message)
 
 
 async def test_fetchone(aconn):
-    async with await aconn.cursor("foo") as cur:
+    async with aconn.cursor("foo") as cur:
         await cur.execute("select generate_series(1, %s) as bar", (2,))
         assert await cur.fetchone() == (1,)
         assert await cur.fetchone() == (2,)
@@ -67,7 +67,7 @@ async def test_fetchone(aconn):
 
 
 async def test_fetchmany(aconn):
-    async with await aconn.cursor("foo") as cur:
+    async with aconn.cursor("foo") as cur:
         await cur.execute("select generate_series(1, %s) as bar", (5,))
         assert await cur.fetchmany(3) == [(1,), (2,), (3,)]
         assert await cur.fetchone() == (4,)
@@ -76,12 +76,12 @@ async def test_fetchmany(aconn):
 
 
 async def test_fetchall(aconn):
-    async with await aconn.cursor("foo") as cur:
+    async with aconn.cursor("foo") as cur:
         await cur.execute("select generate_series(1, %s) as bar", (3,))
         assert await cur.fetchall() == [(1,), (2,), (3,)]
         assert await cur.fetchall() == []
 
-    async with await aconn.cursor("foo") as cur:
+    async with aconn.cursor("foo") as cur:
         await cur.execute("select generate_series(1, %s) as bar", (3,))
         assert await cur.fetchone() == (1,)
         assert await cur.fetchall() == [(2,), (3,)]
@@ -89,7 +89,7 @@ async def test_fetchall(aconn):
 
 
 async def test_rownumber(aconn):
-    cur = await aconn.cursor("foo")
+    cur = aconn.cursor("foo")
     assert cur.rownumber is None
 
     await cur.execute("select 1 from generate_series(1, 42)")
@@ -106,14 +106,14 @@ async def test_rownumber(aconn):
 
 
 async def test_iter(aconn):
-    async with await aconn.cursor("foo") as cur:
+    async with aconn.cursor("foo") as cur:
         await cur.execute("select generate_series(1, %s) as bar", (3,))
         recs = []
         async for rec in cur:
             recs.append(rec)
     assert recs == [(1,), (2,), (3,)]
 
-    async with await aconn.cursor("foo") as cur:
+    async with aconn.cursor("foo") as cur:
         await cur.execute("select generate_series(1, %s) as bar", (3,))
         assert await cur.fetchone() == (1,)
         recs = []
@@ -123,14 +123,14 @@ async def test_iter(aconn):
 
 
 async def test_iter_rownumber(aconn):
-    async with await aconn.cursor("foo") as cur:
+    async with aconn.cursor("foo") as cur:
         await cur.execute("select generate_series(1, %s) as bar", (3,))
         async for row in cur:
             assert cur.rownumber == row[0]
 
 
 async def test_itersize(aconn, acommands):
-    async with await aconn.cursor("foo") as cur:
+    async with aconn.cursor("foo") as cur:
         assert cur.itersize == 100
         cur.itersize = 2
         await cur.execute("select generate_series(1, %s) as bar", (3,))
@@ -145,7 +145,7 @@ async def test_itersize(aconn, acommands):
 
 
 async def test_scroll(aconn):
-    cur = await aconn.cursor("tmp")
+    cur = aconn.cursor("tmp")
     with pytest.raises(aconn.ProgrammingError):
         await cur.scroll(0)
 
@@ -164,7 +164,7 @@ async def test_scroll(aconn):
 
 
 async def test_scrollable(aconn):
-    curs = await aconn.cursor("foo")
+    curs = aconn.cursor("foo")
     await curs.execute("select generate_series(0, 5)")
     await curs.scroll(5)
     for i in range(4, -1, -1):
@@ -174,7 +174,7 @@ async def test_scrollable(aconn):
 
 
 async def test_non_scrollable(aconn):
-    curs = await aconn.cursor("foo")
+    curs = aconn.cursor("foo")
     await curs.execute("select generate_series(0, 5)", scrollable=False)
     await curs.scroll(5)
     with pytest.raises(aconn.OperationalError):
@@ -182,12 +182,12 @@ async def test_non_scrollable(aconn):
 
 
 async def test_steal_cursor(aconn):
-    cur1 = await aconn.cursor()
+    cur1 = aconn.cursor()
     await cur1.execute(
         "declare test cursor without hold for select generate_series(1, 6)"
     )
 
-    cur2 = await aconn.cursor("test")
+    cur2 = aconn.cursor("test")
     # can call fetch without execute
     assert await cur2.fetchone() == (1,)
     assert await cur2.fetchmany(3) == [(2,), (3,), (4,)]
index 231dbfe1a6fea2e7253dfb06a2e831afd500e3a8..c9c4cd48aa2d02d1387a00f2c00dc359ec77b9c9 100644 (file)
@@ -23,7 +23,7 @@ async def test_connection_attributes(aconn, monkeypatch):
 
 
 async def test_dont_prepare(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     for i in range(10):
         await cur.execute("select %s::int", [i], prepare=False)
 
@@ -32,14 +32,14 @@ async def test_dont_prepare(aconn):
 
 
 async def test_do_prepare(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     await cur.execute("select %s::int", [10], prepare=True)
     await cur.execute("select count(*) from pg_prepared_statements")
     assert await cur.fetchone() == (1,)
 
 
 async def test_auto_prepare(aconn):
-    cur = await aconn.cursor()
+    cur = aconn.cursor()
     res = []
     for i in range(10):
         await cur.execute("select count(*) from pg_prepared_statements")
index 48795531ede6764378fac11b9cf92ba7c0fedae1..62563251b53d092093d4a5d425952100e2882edc 100644 (file)
@@ -20,7 +20,7 @@ def insert_row(conn, value):
     else:
 
         async def f():
-            cur = await conn.cursor()
+            cur = conn.cursor()
             await cur.execute(sql, (value,))
 
         return f()
@@ -35,7 +35,7 @@ def inserted(conn):
     else:
 
         async def f():
-            cur = await conn.cursor()
+            cur = conn.cursor()
             await cur.execute(sql)
             rows = await cur.fetchall()
             return set(v for (v,) in rows)
index c955039c9ae8822f227908c227307acb6a34f9c3..92945d77fa66c6045874044e9e335831c1a7ee85 100644 (file)
@@ -324,7 +324,7 @@ async def test_named_savepoints_successful_exit(aconn, acommands):
     assert commands.popall() == ["commit"]
 
     # Case 1 (with a transaction already started)
-    await (await aconn.cursor()).execute("select 1")
+    await aconn.cursor().execute("select 1")
     assert commands.popall() == ["begin"]
     async with aconn.transaction() as tx:
         assert commands.popall() == ['savepoint "_pg3_1"']