throws when java does not have attr.
import logging
-from .case_conversion import _to_camel_case_name
from typing import Callable
from py4j.java_gateway import JavaObject
@@ -15,6 +14,7 @@ class JavaObjectWrapper:
def __getattr__(self, k: str) -> Callable:
self.__check_if_unwrapped(k)
+ self.__check_if_java_has_attr(k)
return self.unwrap().__getattr__(k)
@@ -26,5 +26,9 @@ class JavaObjectWrapper:
"Trying to pass {} to a method that expects a JavaObject - did you forget to call unwrap()?".format(
self.__class__))
+ def __check_if_java_has_attr(self, k: str) -> None:
+ if not k in dir(self.unwrap()):
+ raise AttributeError("{} has no attribute {}".format(self.__class__, k))
+
def unwrap(self) -> JavaObject:
return self._val
