diff --git a/pyproject.toml b/pyproject.toml index 6e0212dc1..7facb67c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ dependencies = [ [project.optional-dependencies] dev = [ "pyright>=1.1.308", - "ruff==0.4.6", + "ruff==0.4.7", "pre-commit==3.3.2", ] examples = [ diff --git a/src/viser/_scene_api.py b/src/viser/_scene_api.py index 019b85fe5..164dfe10b 100644 --- a/src/viser/_scene_api.py +++ b/src/viser/_scene_api.py @@ -1272,17 +1272,16 @@ def add_3d_gui_container( """ # Avoids circular import. - from ._gui_api import GuiApi, _make_unique_id + from ._gui_api import _make_unique_id # New name to make the type checker happy; ViserServer and ClientHandle inherit # from both GuiApi and MessageApi. The pattern below is unideal. - gui_api = self - assert isinstance(gui_api, GuiApi) + gui_api = self._owner.gui # Remove the 3D GUI container if it already exists. This will make sure # contained GUI elements are removed, preventing potential memory leaks. - if name in gui_api._handle_from_node_name: - gui_api._handle_from_node_name[name].remove() + if name in self._handle_from_node_name: + self._handle_from_node_name[name].remove() container_id = _make_unique_id() self._websock_interface.queue_message( diff --git a/src/viser/_scene_handles.py b/src/viser/_scene_handles.py index d6d5d7333..c4b045ed9 100644 --- a/src/viser/_scene_handles.py +++ b/src/viser/_scene_handles.py @@ -273,6 +273,6 @@ def remove(self) -> None: super().remove() # Clean up contained GUI elements. - self._gui_api._container_handle_from_id.pop(self._container_id) - for child in self._children.values(): + for child in tuple(self._children.values()): child.remove() + self._gui_api._container_handle_from_id.pop(self._container_id)