From f6b6c8fecdcd287bffce3cef57e361541ff92c0a Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Mon, 17 Jan 2022 12:26:48 +0100 Subject: [PATCH] `asyncio.iscoroutinefunction` was None in destructor --- neo4j/_async/driver.py | 4 +--- neo4j/_async_compat/util.py | 4 ++++ neo4j/_sync/driver.py | 4 +--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/neo4j/_async/driver.py b/neo4j/_async/driver.py index 70278846b..27a1fdb47 100644 --- a/neo4j/_async/driver.py +++ b/neo4j/_async/driver.py @@ -16,8 +16,6 @@ # limitations under the License. -import asyncio - from .._async_compat.util import AsyncUtil from ..addressing import Address from ..api import READ_ACCESS @@ -197,7 +195,7 @@ async def __aexit__(self, exc_type, exc_value, traceback): await self.close() def __del__(self): - if not asyncio.iscoroutinefunction(self.close): + if not AsyncUtil.is_async_code: self.close() @property diff --git a/neo4j/_async_compat/util.py b/neo4j/_async_compat/util.py index ca432766e..891475d13 100644 --- a/neo4j/_async_compat/util.py +++ b/neo4j/_async_compat/util.py @@ -45,6 +45,8 @@ async def callback(cb, *args, **kwargs): experimental_async = experimental + is_async_code = True + class Util: iter = iter @@ -61,3 +63,5 @@ def experimental_async(message): def f_(f): return f return f_ + + is_async_code = False diff --git a/neo4j/_sync/driver.py b/neo4j/_sync/driver.py index 7a805280b..42a3c0ac7 100644 --- a/neo4j/_sync/driver.py +++ b/neo4j/_sync/driver.py @@ -16,8 +16,6 @@ # limitations under the License. -import asyncio - from .._async_compat.util import Util from ..addressing import Address from ..api import READ_ACCESS @@ -197,7 +195,7 @@ def __exit__(self, exc_type, exc_value, traceback): self.close() def __del__(self): - if not asyncio.iscoroutinefunction(self.close): + if not Util.is_async_code: self.close() @property