mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 12:18:02 +00:00
entity_instance: get_info_2 falls back to get_info for unsupported args #4270
get_info_2 advertises the same signature as get_info but raised a bare AssertionError for anything the C++ fast path does not implement -- including its own default arguments (recursive=False). Use the fast path when recursive=True, return_type=dict and ignore=() hold, and delegate to the pure Python get_info otherwise. As noted in the issue, without recursion there is no meaningful performance gain to lose by delegating. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
committed by
Thomas Krijnen
parent
fa597536e1
commit
58cfab48e6
@@ -642,16 +642,16 @@ class entity_instance:
|
|||||||
return_type: type[dict] = dict,
|
return_type: type[dict] = dict,
|
||||||
ignore: Sequence[str] = (),
|
ignore: Sequence[str] = (),
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""More perfomant version of `.get_info()` but with limited arguments values.\n
|
"""More perfomant version of `.get_info()`.\n
|
||||||
Method has exactly the same signature as `.get_info()` but it doesn't support getting information non-recursively.
|
Method has exactly the same signature as `.get_info()`, but the fast C++
|
||||||
|
path only implements ``recursive=True``, ``return_type=dict`` and
|
||||||
Currently supported arguments values:
|
``ignore=()``. Any other combination falls back to the pure Python
|
||||||
* recursive: `True` (will fail with default `False` value from `.get_info()`)
|
`.get_info()`, where no meaningful performance gain is possible anyway
|
||||||
* return_type: `dict`
|
as the cost is dominated by the recursive traversal.
|
||||||
* ignore: `()` (empty tuple)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert recursive
|
if recursive and return_type is dict and not ignore:
|
||||||
assert return_type is dict
|
return ifcopenshell_wrapper.get_info_cpp(self.wrapped_data, include_identifier)
|
||||||
assert len(ignore) == 0
|
return self.get_info(
|
||||||
return ifcopenshell_wrapper.get_info_cpp(self.wrapped_data, include_identifier)
|
include_identifier=include_identifier, recursive=recursive, return_type=return_type, ignore=ignore
|
||||||
|
)
|
||||||
|
|||||||
@@ -64,3 +64,14 @@ class TestGetInfo2(test.bootstrap.IFC4):
|
|||||||
"Outer": {"CfsFaces": None, "type": "IfcClosedShell"},
|
"Outer": {"CfsFaces": None, "type": "IfcClosedShell"},
|
||||||
"type": "IfcFacetedBrep",
|
"type": "IfcFacetedBrep",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def test_unsupported_arguments_fall_back_to_get_info(self):
|
||||||
|
# Regression test for #4270: get_info_2 raised a bare AssertionError
|
||||||
|
# when called with its own default arguments (recursive=False) or any
|
||||||
|
# other combination the C++ fast path does not implement. It must
|
||||||
|
# delegate to get_info instead of crashing.
|
||||||
|
brep = self.file.create_entity("IfcFacetedBrep")
|
||||||
|
shell = self.file.create_entity("IfcClosedShell")
|
||||||
|
brep.Outer = shell
|
||||||
|
assert brep.get_info_2() == brep.get_info()
|
||||||
|
assert brep.get_info_2(recursive=True, ignore=("Outer",)) == brep.get_info(recursive=True, ignore=("Outer",))
|
||||||
|
|||||||
Reference in New Issue
Block a user