Skip to content

feat: removing cached_property for bodies #2122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/2122.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removing cached_property for bodies
1 change: 0 additions & 1 deletion src/ansys/geometry/core/designer/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,6 @@ def copy(self, parent: "Component", name: str = None) -> "Body": # noqa: D102
response.get("master_id"), copy_name, self._grpc_client, is_surface=self.is_surface
)
parent._master_component.part.bodies.append(tb)
parent._clear_cached_bodies()
body_id = f"{parent.id}/{tb.id}" if parent.parent_component else tb.id
return Body(body_id, response.get("name"), parent, tb)

Expand Down
20 changes: 9 additions & 11 deletions src/ansys/geometry/core/designer/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"""Provides for managing components."""

from enum import Enum, unique
from functools import cached_property
from typing import TYPE_CHECKING, Any, Optional, Union
import uuid

Expand Down Expand Up @@ -251,11 +250,6 @@ def __init__(

self._master_component.occurrences.append(self)

def _clear_cached_bodies(self) -> None:
"""Clear the cached bodies."""
if "bodies" in self.__dict__:
del self.__dict__["bodies"]

@property
def id(self) -> str:
"""ID of the component."""
Expand Down Expand Up @@ -305,14 +299,20 @@ def components(self) -> list["Component"]:
"""List of ``Component`` objects inside of the component."""
return self._components

@cached_property
@property
def bodies(self) -> list[Body]:
"""List of ``Body`` objects inside of the component."""
bodies = []
for body in self._master_component.part.bodies:
id = f"{self.id}/{body.id}" if self.parent_component else body.id
if body.is_alive:
bodies.append(Body(id, body.name, self, body))
bodies.append(
Body(
f"{self.id}/{body.id}" if self.parent_component else body.id,
body.name,
self,
body,
)
)
return bodies

@property
Expand Down Expand Up @@ -539,7 +539,6 @@ def __build_body_from_response(self, response: dict) -> Body:
is_surface=response["is_surface"],
)
self._master_component.part.bodies.append(tb)
self._clear_cached_bodies()
return Body(response["id"], response["name"], self, tb)

@check_input_types
Expand Down Expand Up @@ -1335,7 +1334,6 @@ def delete_body(self, body: Body | str) -> None:
# on the client side
body_requested._is_alive = False
self._grpc_client.log.debug(f"Body {body_requested.id} has been deleted.")
self._clear_cached_bodies()
else:
self._grpc_client.log.warning(
f"Body {id} is not found in this component (or subcomponents)."
Expand Down
1 change: 0 additions & 1 deletion src/ansys/geometry/core/designer/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,6 @@ def _update_design_inplace(self) -> None:
# https://github.com/ansys/pyansys-geometry/issues/1319
#
self._components = []
self._clear_cached_bodies()
self._materials = []
self._named_selections = {}
self._coordinate_systems = {}
Expand Down
Loading