From: Daniele Varrazzo Date: Mon, 22 Nov 2021 01:23:36 +0000 (+0100) Subject: Use an empty string instead on None in the copy work queue X-Git-Tag: 3.0.5~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=264475a64c2284e3f125d330ead39de960399431;p=thirdparty%2Fpsycopg.git Use an empty string instead on None in the copy work queue The test for copy end is just "if not item", so the empty string is actually never used as a piece of data. This simplifies the type of the queue. --- diff --git a/psycopg/psycopg/copy.py b/psycopg/psycopg/copy.py index 572b9699d..189f70d75 100644 --- a/psycopg/psycopg/copy.py +++ b/psycopg/psycopg/copy.py @@ -168,9 +168,7 @@ class Copy(BaseCopy["Connection[Any]"]): def __init__(self, cursor: "Cursor[Any]"): super().__init__(cursor) - self._queue: queue.Queue[Optional[bytes]] = queue.Queue( - maxsize=self.QUEUE_SIZE - ) + self._queue: queue.Queue[bytes] = queue.Queue(maxsize=self.QUEUE_SIZE) self._worker: Optional[threading.Thread] = None def __enter__(self) -> "Copy": @@ -286,7 +284,7 @@ class Copy(BaseCopy["Connection[Any]"]): def _write_end(self) -> None: data = self.formatter.end() self._write(data) - self._queue.put(None) + self._queue.put(b"") if self._worker: self._worker.join() @@ -300,7 +298,7 @@ class AsyncCopy(BaseCopy["AsyncConnection[Any]"]): def __init__(self, cursor: "AsyncCursor[Any]"): super().__init__(cursor) - self._queue: asyncio.Queue[Optional[bytes]] = asyncio.Queue( + self._queue: asyncio.Queue[bytes] = asyncio.Queue( maxsize=self.QUEUE_SIZE ) self._worker: Optional[asyncio.Future[None]] = None @@ -380,7 +378,7 @@ class AsyncCopy(BaseCopy["AsyncConnection[Any]"]): async def _write_end(self) -> None: data = self.formatter.end() await self._write(data) - await self._queue.put(None) + await self._queue.put(b"") if self._worker: await asyncio.gather(self._worker)