From 02bf62c833e094fecd33e54e53956658ce8847de Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Thu, 18 Aug 2022 08:42:13 +0200 Subject: [PATCH 1/2] Fix #776: fix sync socket close helper method --- neo4j/_async_compat/network/_bolt_socket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo4j/_async_compat/network/_bolt_socket.py b/neo4j/_async_compat/network/_bolt_socket.py index 279ec0bd0..81f4d2080 100644 --- a/neo4j/_async_compat/network/_bolt_socket.py +++ b/neo4j/_async_compat/network/_bolt_socket.py @@ -605,7 +605,7 @@ def _handshake(cls, s, resolved_address): def close_socket(cls, socket_): try: if isinstance(socket_, BoltSocket): - socket.close() + socket_.close() else: socket_.shutdown(SHUT_RDWR) socket_.close() From b04c311ecf9f9e618b3491ce71bf2925a150cfed Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Thu, 18 Aug 2022 08:48:24 +0200 Subject: [PATCH 2/2] Improve type hints in socket wrapper classes --- neo4j/_async_compat/network/_bolt_socket.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/neo4j/_async_compat/network/_bolt_socket.py b/neo4j/_async_compat/network/_bolt_socket.py index 81f4d2080..62a536903 100644 --- a/neo4j/_async_compat/network/_bolt_socket.py +++ b/neo4j/_async_compat/network/_bolt_socket.py @@ -43,6 +43,9 @@ if t.TYPE_CHECKING: import typing_extensions as te + from ..._async.io import AsyncBolt + from ..._sync.io import Bolt + from ... import addressing from ..._deadline import Deadline from ..._exceptions import ( @@ -75,7 +78,7 @@ def _sanitize_deadline(deadline): class AsyncBoltSocket: - Bolt: te.Final[t.Type] = None # type: ignore[assignment] + Bolt: te.Final[t.Type[AsyncBolt]] = None # type: ignore[assignment] def __init__(self, reader, protocol, writer): self._reader = reader # type: asyncio.StreamReader @@ -405,7 +408,7 @@ async def connect(cls, address, *, timeout, custom_resolver, ssl_context, class BoltSocket: - Bolt: te.Final[t.Type] = None # type: ignore[assignment] + Bolt: te.Final[t.Type[Bolt]] = None # type: ignore[assignment] def __init__(self, socket_: socket): self._socket = socket_