Skip to content

Commit

Permalink
function to directly check if object is subclassed
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianPython committed Apr 25, 2022
1 parent b32fa40 commit 9ae84dd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pyoracle_forms/__init__.py
Expand Up @@ -44,7 +44,7 @@
from .misc import registered_objects
from .property_types import Properties

__version__ = "0.3.3"
__version__ = "0.3.4"


def initialize_context(version: str = "12c", encoding: str = "utf-8") -> None:
Expand Down
23 changes: 16 additions & 7 deletions pyoracle_forms/context.py
Expand Up @@ -124,15 +124,24 @@ def _handled_api_function(*args: Any) -> Any: # type: ignore
return _handled_api_function


def has_property(generic_object: BaseObject, property_number: int) -> bool:
func = api_function("d2fobhp_HasProp", (c_void_p, c_int))
result = func(generic_object, property_number)

def handle_return_value(result: int) -> bool:
if result in (2, 3): # YES, NO
return bool(result == 2)
raise_for_code(result)


def is_subclassed(generic_object: BaseObject) -> bool:
func = api_function("d2fobis_IsSubclassed", (c_void_p,))
result = func(generic_object)
return handle_return_value(result)


def has_property(generic_object: BaseObject, property_number: int) -> bool:
func = api_function("d2fobhp_HasProp", (c_void_p, c_int))
result = func(generic_object, property_number)
return handle_return_value(result)


def setter(function_name: str, setter_type: CTypes) -> Setter[T]:
return handled_api_function(function_name, (c_void_p, c_int, setter_type))

Expand Down Expand Up @@ -223,9 +232,9 @@ def property_type(property_number: int) -> int:


def property_constant_number(property_const_name: str) -> int:
return handled_api_function("d2fprgcv_GetConstValue", (c_char_p, c_void_p), 1)(
property_const_name.encode("utf-8"), c_int()
).value
return handled_api_function(
"d2fprgcv_GetConstValue", (c_char_p, c_void_p), return_value_index=1
)(property_const_name.encode("utf-8"), c_int()).value


def object_number(obj_name: str) -> int:
Expand Down
5 changes: 3 additions & 2 deletions pyoracle_forms/generic_object.py
Expand Up @@ -11,6 +11,7 @@
from .context import set_subclass
from .context import move
from .context import query_type
from .context import is_subclassed

from .property_types import Properties

Expand Down Expand Up @@ -112,8 +113,8 @@ def is_property_inherited(self, property_type: Properties) -> NoReturn:
def is_property_default(self, property_type: Properties) -> NoReturn:
raise NotImplementedError()

def is_subclassed(self) -> NoReturn:
raise NotImplementedError()
def is_subclassed(self) -> bool:
return is_subclassed(self)

def __repr__(self) -> str:
return f"{self.__class__.__name__}({repr(self._as_parameter_)})"
Expand Down
5 changes: 0 additions & 5 deletions tests/test_item.py
Expand Up @@ -93,8 +93,3 @@ def test_is_property_inherited(new_item):
@pytest.mark.xfail
def test_is_property_default(new_item):
assert new_item.is_property_default(Properties.x_position)


@pytest.mark.xfail
def test_is_subclassed(new_item):
assert new_item.is_subclassed()
8 changes: 8 additions & 0 deletions tests/test_subclass.py
Expand Up @@ -11,3 +11,11 @@ def test_un_subclass(subclassed_item):

assert subclass.source_object != subclass
assert not subclassed_item.source_object


def test_is_not_subclassed(new_item):
assert not new_item.is_subclassed()


def test_is_subclassed(subclassed_item):
assert subclassed_item.is_subclassed()

0 comments on commit 9ae84dd

Please sign in to comment.