From: Daniele Varrazzo Date: Wed, 7 Dec 2022 20:33:46 +0000 (+0000) Subject: chore: declare Copy.read to return a buffer object X-Git-Tag: 3.1.5~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22b4e708481fc9fb3183f5cfd259883ad51a92a0;p=thirdparty%2Fpsycopg.git chore: declare Copy.read to return a buffer object We still return memoryview, but leave the possibility open to return something different, such as bytes. --- diff --git a/psycopg/psycopg/copy.py b/psycopg/psycopg/copy.py index 274b20083..751430664 100644 --- a/psycopg/psycopg/copy.py +++ b/psycopg/psycopg/copy.py @@ -148,7 +148,7 @@ class BaseCopy(Generic[ConnectionType]): # High level copy protocol generators (state change of the Copy object) - def _read_gen(self) -> PQGen[memoryview]: + def _read_gen(self) -> PQGen[Buffer]: if self._finished: return memoryview(b"") @@ -250,7 +250,7 @@ class Copy(BaseCopy["Connection[Any]"]): # End user sync interface - def __iter__(self) -> Iterator[memoryview]: + def __iter__(self) -> Iterator[Buffer]: """Implement block-by-block iteration on :sql:`COPY TO`.""" while True: data = self.read() @@ -258,7 +258,7 @@ class Copy(BaseCopy["Connection[Any]"]): break yield data - def read(self) -> memoryview: + def read(self) -> Buffer: """ Read an unparsed row after a :sql:`COPY TO` operation. @@ -498,14 +498,14 @@ class AsyncCopy(BaseCopy["AsyncConnection[Any]"]): ) -> None: await self.finish(exc_val) - async def __aiter__(self) -> AsyncIterator[memoryview]: + async def __aiter__(self) -> AsyncIterator[Buffer]: while True: data = await self.read() if not data: break yield data - async def read(self) -> memoryview: + async def read(self) -> Buffer: return await self.connection.wait(self._read_gen()) async def rows(self) -> AsyncIterator[Tuple[Any, ...]]: