From 8ef9d4a697cd2ec8b8bde078945297880d0d567b Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Mon, 28 Oct 2024 12:02:20 -0500 Subject: [PATCH 1/2] Files: Remove unnecessary return in a try/finally statement - That was preventing other errors generated there to be raised. - Also, replace old EnvironmentError by OSError. --- spyder/plugins/explorer/widgets/explorer.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spyder/plugins/explorer/widgets/explorer.py b/spyder/plugins/explorer/widgets/explorer.py index da5cac5c018..da1d1c0b554 100644 --- a/spyder/plugins/explorer/widgets/explorer.py +++ b/spyder/plugins/explorer/widgets/explorer.py @@ -1307,7 +1307,7 @@ def create_new_folder(self, current_path, title, subtitle, is_package): dirname = osp.join(current_path, str(name)) try: os.mkdir(dirname) - except EnvironmentError as error: + except OSError as error: QMessageBox.critical( self, title, _("Unable to create folder %s" @@ -1319,8 +1319,7 @@ def create_new_folder(self, current_path, title, subtitle, is_package): try: with open(fname, 'wb') as f: f.write(to_binary_string('#')) - return dirname - except EnvironmentError as error: + except OSError as error: QMessageBox.critical( self, title, _("Unable to create file %s" From 152ada4c7353c17a25895a8d7aecb70f2b3b13ed Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Mon, 28 Oct 2024 12:02:50 -0500 Subject: [PATCH 2/2] Files: Improve code formatting a bit in create_new_folder method --- spyder/plugins/explorer/widgets/explorer.py | 30 ++++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/spyder/plugins/explorer/widgets/explorer.py b/spyder/plugins/explorer/widgets/explorer.py index da1d1c0b554..2bbbf22e312 100644 --- a/spyder/plugins/explorer/widgets/explorer.py +++ b/spyder/plugins/explorer/widgets/explorer.py @@ -1301,18 +1301,24 @@ def create_new_folder(self, current_path, title, subtitle, is_package): current_path = '' if osp.isfile(current_path): current_path = osp.dirname(current_path) - name, valid = QInputDialog.getText(self, title, subtitle, - QLineEdit.Normal, "") + name, valid = QInputDialog.getText( + self, title, subtitle, QLineEdit.Normal, "" + ) + if valid: dirname = osp.join(current_path, str(name)) try: os.mkdir(dirname) except OSError as error: QMessageBox.critical( - self, title, - _("Unable to create folder %s" - "

Error message:
%s" - ) % (dirname, str(error))) + self, + title, + _( + "Unable to create folder %s" + "

Error message:
%s" + ) + % (dirname, str(error)), + ) finally: if is_package: fname = osp.join(dirname, '__init__.py') @@ -1321,10 +1327,14 @@ def create_new_folder(self, current_path, title, subtitle, is_package): f.write(to_binary_string('#')) except OSError as error: QMessageBox.critical( - self, title, - _("Unable to create file %s" - "

Error message:
%s" - ) % (fname, str(error))) + self, + title, + _( + "Unable to create file %s" + "

Error message:
%s" + ) + % (fname, str(error)), + ) def get_selected_dir(self): """ Get selected dir