Skip to content

Commit 9ae84dd

Browse files
committed
function to directly check if object is subclassed
1 parent b32fa40 commit 9ae84dd

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

pyoracle_forms/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from .misc import registered_objects
4545
from .property_types import Properties
4646

47-
__version__ = "0.3.3"
47+
__version__ = "0.3.4"
4848

4949

5050
def initialize_context(version: str = "12c", encoding: str = "utf-8") -> None:

pyoracle_forms/context.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,24 @@ def _handled_api_function(*args: Any) -> Any: # type: ignore
124124
return _handled_api_function
125125

126126

127-
def has_property(generic_object: BaseObject, property_number: int) -> bool:
128-
func = api_function("d2fobhp_HasProp", (c_void_p, c_int))
129-
result = func(generic_object, property_number)
130-
127+
def handle_return_value(result: int) -> bool:
131128
if result in (2, 3): # YES, NO
132129
return bool(result == 2)
133130
raise_for_code(result)
134131

135132

133+
def is_subclassed(generic_object: BaseObject) -> bool:
134+
func = api_function("d2fobis_IsSubclassed", (c_void_p,))
135+
result = func(generic_object)
136+
return handle_return_value(result)
137+
138+
139+
def has_property(generic_object: BaseObject, property_number: int) -> bool:
140+
func = api_function("d2fobhp_HasProp", (c_void_p, c_int))
141+
result = func(generic_object, property_number)
142+
return handle_return_value(result)
143+
144+
136145
def setter(function_name: str, setter_type: CTypes) -> Setter[T]:
137146
return handled_api_function(function_name, (c_void_p, c_int, setter_type))
138147

@@ -223,9 +232,9 @@ def property_type(property_number: int) -> int:
223232

224233

225234
def property_constant_number(property_const_name: str) -> int:
226-
return handled_api_function("d2fprgcv_GetConstValue", (c_char_p, c_void_p), 1)(
227-
property_const_name.encode("utf-8"), c_int()
228-
).value
235+
return handled_api_function(
236+
"d2fprgcv_GetConstValue", (c_char_p, c_void_p), return_value_index=1
237+
)(property_const_name.encode("utf-8"), c_int()).value
229238

230239

231240
def object_number(obj_name: str) -> int:

pyoracle_forms/generic_object.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .context import set_subclass
1212
from .context import move
1313
from .context import query_type
14+
from .context import is_subclassed
1415

1516
from .property_types import Properties
1617

@@ -112,8 +113,8 @@ def is_property_inherited(self, property_type: Properties) -> NoReturn:
112113
def is_property_default(self, property_type: Properties) -> NoReturn:
113114
raise NotImplementedError()
114115

115-
def is_subclassed(self) -> NoReturn:
116-
raise NotImplementedError()
116+
def is_subclassed(self) -> bool:
117+
return is_subclassed(self)
117118

118119
def __repr__(self) -> str:
119120
return f"{self.__class__.__name__}({repr(self._as_parameter_)})"

tests/test_item.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,3 @@ def test_is_property_inherited(new_item):
9393
@pytest.mark.xfail
9494
def test_is_property_default(new_item):
9595
assert new_item.is_property_default(Properties.x_position)
96-
97-
98-
@pytest.mark.xfail
99-
def test_is_subclassed(new_item):
100-
assert new_item.is_subclassed()

tests/test_subclass.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ def test_un_subclass(subclassed_item):
1111

1212
assert subclass.source_object != subclass
1313
assert not subclassed_item.source_object
14+
15+
16+
def test_is_not_subclassed(new_item):
17+
assert not new_item.is_subclassed()
18+
19+
20+
def test_is_subclassed(subclassed_item):
21+
assert subclassed_item.is_subclassed()

0 commit comments

Comments
 (0)