Skip to content

Commit 16109e2

Browse files
fix: check_input_types not working with forward refs (#1471)
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
1 parent 2435173 commit 16109e2

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

doc/changelog.d/1471.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``check_input_types`` not working with forward refs

src/ansys/geometry/core/tools/prepare_tools.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
from typing import TYPE_CHECKING
2525

26-
from beartype import beartype as check_input_types
2726
from google.protobuf.wrappers_pb2 import BoolValue, DoubleValue
2827

2928
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
@@ -41,7 +40,7 @@
4140
get_design_from_edge,
4241
get_design_from_face,
4342
)
44-
from ansys.geometry.core.misc.checks import min_backend_version
43+
from ansys.geometry.core.misc.checks import check_type_all_elements_in_iterable, min_backend_version
4544
from ansys.geometry.core.typing import Real
4645

4746
if TYPE_CHECKING: # pragma: no cover
@@ -65,7 +64,6 @@ def __init__(self, grpc_client: GrpcClient):
6564
self._prepare_stub = PrepareToolsStub(self._grpc_client.channel)
6665

6766
@protect_grpc
68-
@check_input_types
6967
@min_backend_version(25, 1, 0)
7068
def extract_volume_from_faces(
7169
self, sealing_faces: list["Face"], inside_faces: list["Face"]
@@ -87,10 +85,16 @@ def extract_volume_from_faces(
8785
list[Body]
8886
List of created bodies.
8987
"""
88+
from ansys.geometry.core.designer.face import Face
89+
9090
if not sealing_faces or not inside_faces:
9191
self._grpc_client.log.info("No sealing faces or inside faces provided...")
9292
return []
9393

94+
# Verify inputs
95+
check_type_all_elements_in_iterable(sealing_faces, Face)
96+
check_type_all_elements_in_iterable(inside_faces, Face)
97+
9498
parent_design = get_design_from_face(sealing_faces[0])
9599

96100
response = self._prepare_stub.ExtractVolumeFromFaces(
@@ -110,10 +114,9 @@ def extract_volume_from_faces(
110114
return []
111115

112116
@protect_grpc
113-
@check_input_types
114117
@min_backend_version(25, 1, 0)
115118
def extract_volume_from_edge_loops(
116-
self, sealing_edges: list["Edge"], inside_faces: list["Face"]
119+
self, sealing_edges: list["Edge"], inside_faces: list["Face"] = None
117120
) -> list["Body"]:
118121
"""Extract a volume from input edge loops.
119122
@@ -124,18 +127,28 @@ def extract_volume_from_edge_loops(
124127
----------
125128
sealing_edges : list[Edge]
126129
List of faces that seal the volume.
127-
inside_faces : list[Face]
128-
List of faces that define the interior of the solid (Not always necessary).
130+
inside_faces : list[Face], optional
131+
List of faces that define the interior of the solid (not always necessary).
129132
130133
Returns
131134
-------
132135
list[Body]
133136
List of created bodies.
134137
"""
138+
from ansys.geometry.core.designer.edge import Edge
139+
from ansys.geometry.core.designer.face import Face
140+
135141
if not sealing_edges:
136142
self._grpc_client.log.info("No sealing edges provided...")
137143
return []
138144

145+
# Assign default values to inside_faces
146+
inside_faces = [] if inside_faces is None else inside_faces
147+
148+
# Verify inputs
149+
check_type_all_elements_in_iterable(sealing_edges, Edge)
150+
check_type_all_elements_in_iterable(inside_faces, Face)
151+
139152
parent_design = get_design_from_edge(sealing_edges[0])
140153

141154
response = self._prepare_stub.ExtractVolumeFromEdgeLoops(
@@ -155,7 +168,6 @@ def extract_volume_from_edge_loops(
155168
return []
156169

157170
@protect_grpc
158-
@check_input_types
159171
@min_backend_version(24, 2, 0)
160172
def share_topology(
161173
self, bodies: list["Body"], tol: Real = 0.0, preserve_instances: bool = False
@@ -176,9 +188,14 @@ def share_topology(
176188
bool
177189
``True`` if successful, ``False`` if failed.
178190
"""
191+
from ansys.geometry.core.designer.body import Body
192+
179193
if not bodies:
180194
return False
181195

196+
# Verify inputs
197+
check_type_all_elements_in_iterable(bodies, Body)
198+
182199
share_topo_response = self._prepare_stub.ShareTopology(
183200
ShareTopologyRequest(
184201
selection=[GRPCBody(id=body.id) for body in bodies],

tests/integration/test_prepare_tools.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ def test_volume_extract_from_edge_loops(modeler: Modeler):
4949
design = modeler.open_file(FILES_DIR / "hollowCylinder.scdocx")
5050

5151
body = design.bodies[0]
52-
inside_faces = []
5352
sealing_edges = [body.edges[2], body.edges[3]]
5453
created_bodies = modeler.prepare_tools.extract_volume_from_edge_loops(
5554
sealing_edges,
56-
inside_faces,
5755
)
5856

5957
assert len(created_bodies) == 1

0 commit comments

Comments
 (0)