From 07e312e448e54b3c4aab5069b0e662ec262a4ee6 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Mon, 11 Jul 2022 13:26:24 -0500 Subject: [PATCH 1/2] Registry: Don't double validate if plugins can be deleted/closed --- spyder/api/plugin_registration/registry.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/spyder/api/plugin_registration/registry.py b/spyder/api/plugin_registration/registry.py index 0eaf949dbe7..f876c63cd13 100644 --- a/spyder/api/plugin_registration/registry.py +++ b/spyder/api/plugin_registration/registry.py @@ -446,7 +446,8 @@ def dock_undocked_plugin( # Close undocked plugins. plugin_instance._close_window() - def delete_plugin(self, plugin_name: str, teardown: bool = True) -> bool: + def delete_plugin(self, plugin_name: str, teardown: bool = True, + check_can_delete: bool = True) -> bool: """ Remove and delete a plugin from the registry by its name. @@ -457,6 +458,9 @@ def delete_plugin(self, plugin_name: str, teardown: bool = True) -> bool: teardown: bool True if the teardown notification to other plugins should be sent when deleting the plugin, False otherwise. + check_can_delete: bool + True if the plugin should validate if can be closed in the moment, + False otherwise. Returns ------- @@ -468,9 +472,10 @@ def delete_plugin(self, plugin_name: str, teardown: bool = True) -> bool: plugin_instance = self.plugin_registry[plugin_name] # Determine if plugin can be closed - can_delete = self.can_delete_plugin(plugin_name) - if not can_delete: - return False + if check_can_delete: + can_delete = self.can_delete_plugin(plugin_name) + if not can_delete: + return False if isinstance(plugin_instance, SpyderPluginV2): # Cleanly delete plugin widgets. This avoids segfautls with @@ -637,7 +642,7 @@ def delete_all_plugins(self, excluding: Optional[Set[str]] = None, plugin_instance = self.plugin_registry[plugin_name] if isinstance(plugin_instance, SpyderPlugin): can_close &= self.delete_plugin( - plugin_name, teardown=False) + plugin_name, teardown=False, check_can_delete=False) if not can_close and not close_immediately: break @@ -650,7 +655,7 @@ def delete_all_plugins(self, excluding: Optional[Set[str]] = None, plugin_instance = self.plugin_registry[plugin_name] if isinstance(plugin_instance, SpyderPlugin): can_close &= self.delete_plugin( - plugin_name, teardown=False) + plugin_name, teardown=False, check_can_delete=False) if not can_close and not close_immediately: break @@ -663,7 +668,7 @@ def delete_all_plugins(self, excluding: Optional[Set[str]] = None, plugin_instance = self.plugin_registry[plugin_name] if isinstance(plugin_instance, SpyderPluginV2): can_close &= self.delete_plugin( - plugin_name, teardown=False) + plugin_name, teardown=False, check_can_delete=False) if not can_close and not close_immediately: break @@ -676,7 +681,7 @@ def delete_all_plugins(self, excluding: Optional[Set[str]] = None, plugin_instance = self.plugin_registry[plugin_name] if isinstance(plugin_instance, SpyderPluginV2): can_close &= self.delete_plugin( - plugin_name, teardown=False) + plugin_name, teardown=False, check_can_delete=False) if not can_close and not close_immediately: break From ba5eeec870fbca800cb495677135a776b7fa0d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Althviz=20Mor=C3=A9?= Date: Mon, 11 Jul 2022 14:06:19 -0500 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Carlos Cordoba --- spyder/api/plugin_registration/registry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spyder/api/plugin_registration/registry.py b/spyder/api/plugin_registration/registry.py index f876c63cd13..8699b735951 100644 --- a/spyder/api/plugin_registration/registry.py +++ b/spyder/api/plugin_registration/registry.py @@ -459,8 +459,8 @@ def delete_plugin(self, plugin_name: str, teardown: bool = True, True if the teardown notification to other plugins should be sent when deleting the plugin, False otherwise. check_can_delete: bool - True if the plugin should validate if can be closed in the moment, - False otherwise. + True if the plugin should validate if it can be closed when this + method is called, False otherwise. Returns -------