From 67421f46fa39273dc3165dd11005a6ac423570ea Mon Sep 17 00:00:00 2001 From: Arman Farhangi Date: Fri, 15 Mar 2024 12:21:26 -0700 Subject: [PATCH] Change SafeCloseable to AutoCloseable --- py/server/deephaven/jcompat.py | 16 ++++++++-------- py/server/tests/test_jcompat.py | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/py/server/deephaven/jcompat.py b/py/server/deephaven/jcompat.py index 7ab86dd9522..46cb3d79a3a 100644 --- a/py/server/deephaven/jcompat.py +++ b/py/server/deephaven/jcompat.py @@ -306,15 +306,15 @@ def _j_array_to_series(dtype: DType, j_array: jpy.JType, conv_null: bool) -> pd. return s -class SafeCloseable(JObjectWrapper): - """A context manager wrapper to allow Java SafeCloseable to be used in with statements. +class AutoCloseable(JObjectWrapper): + """A context manager wrapper to allow Java AutoCloseable to be used in with statements. - When constructing a new instance, the Java SafeCloseable must not be closed.""" + When constructing a new instance, the Java AutoCloseable must not be closed.""" - j_object_type = jpy.get_type("io.deephaven.util.SafeCloseable") + j_object_type = jpy.get_type("java.lang.AutoCloseable") - def __init__(self, j_safe_closeable): - self._j_safe_closeable = j_safe_closeable + def __init__(self, j_auto_closeable): + self._j_auto_closeable = j_auto_closeable self.closed = False def __enter__(self): @@ -323,7 +323,7 @@ def __enter__(self): def close(self): if not self.closed: self.closed = True - self._j_safe_closeable.close() + self._j_auto_closeable.close() def __exit__(self, exc_type, exc_value, traceback): self.close() @@ -333,4 +333,4 @@ def __del__(self): @property def j_object(self) -> jpy.JType: - return self._j_safe_closeable + return self._j_auto_closeable diff --git a/py/server/tests/test_jcompat.py b/py/server/tests/test_jcompat.py index 8f28b431639..40241b73da2 100644 --- a/py/server/tests/test_jcompat.py +++ b/py/server/tests/test_jcompat.py @@ -5,7 +5,7 @@ import unittest from deephaven import dtypes -from deephaven.jcompat import j_function, j_lambda, SafeCloseable +from deephaven.jcompat import j_function, j_lambda, AutoCloseable from tests.testbase import BaseTestCase import jpy @@ -30,11 +30,11 @@ def int_to_str(v: int) -> str: r = j_func.apply(10) self.assertEqual(r, "10") - def test_safe_closeable(self): - safe_closeable = SafeCloseable(_JSharedContext.makeSharedContext()) - with safe_closeable: - self.assertEqual(safe_closeable.closed, False) - self.assertEqual(safe_closeable.closed, True) + def test_auto_closeable(self): + auto_closeable = AutoCloseable(_JSharedContext.makeSharedContext()) + with auto_closeable: + self.assertEqual(auto_closeable.closed, False) + self.assertEqual(auto_closeable.closed, True) if __name__ == "__main__":