Skip to content
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

PR: Remove unnecessary return in a try/finally statement (Files) #22745

Merged
merged 2 commits into from
Oct 28, 2024
Merged
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
35 changes: 22 additions & 13 deletions spyder/plugins/explorer/widgets/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,31 +1301,40 @@ 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 EnvironmentError as error:
except OSError as error:
QMessageBox.critical(
self, title,
_("<b>Unable to create folder <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (dirname, str(error)))
self,
title,
_(
"<b>Unable to create folder <i>%s</i></b>"
"<br><br>Error message:<br>%s"
)
% (dirname, str(error)),
)
finally:
if is_package:
fname = osp.join(dirname, '__init__.py')
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,
_("<b>Unable to create file <i>%s</i></b>"
"<br><br>Error message:<br>%s"
) % (fname, str(error)))
self,
title,
_(
"<b>Unable to create file <i>%s</i></b>"
"<br><br>Error message:<br>%s"
)
% (fname, str(error)),
)

def get_selected_dir(self):
""" Get selected dir
Expand Down
Loading