Skip to content

Commit

Permalink
fix changes according to review
Browse files Browse the repository at this point in the history
- rename ext variable to more explicit extension
- rename ext in iimport_data to extension too for consistency
- add comment for related issue #7196
  • Loading branch information
maurerle committed Jul 14, 2022
1 parent c91c218 commit 31136ab
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions spyder/plugins/variableexplorer/widgets/namespacebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,27 @@ def import_data(self, filenames=None):
self.filename = str(filename)
if os.name == "nt":
self.filename = remove_backslashes(self.filename)
ext = osp.splitext(self.filename)[1].lower()
extension = osp.splitext(self.filename)[1].lower()

if ext not in iofunctions.load_funcs:
if extension not in iofunctions.load_funcs:
buttons = QMessageBox.Yes | QMessageBox.Cancel
answer = QMessageBox.question(self, title,
_("<b>Unsupported file extension '%s'</b><br><br>"
"Would you like to import it anyway "
"(by selecting a known file format)?"
) % ext, buttons)
) % extension, buttons)
if answer == QMessageBox.Cancel:
return
formats = list(iofunctions.load_extensions.keys())
item, ok = QInputDialog.getItem(self, title,
_('Open file as:'),
formats, 0, False)
if ok:
ext = iofunctions.load_extensions[str(item)]
extension = iofunctions.load_extensions[str(item)]
else:
return

load_func = iofunctions.load_funcs[ext]
load_func = iofunctions.load_funcs[extension]

# 'import_wizard' (self.setup_io)
if isinstance(load_func, str):
Expand All @@ -220,7 +220,7 @@ def import_data(self, filenames=None):
else:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
QApplication.processEvents()
error_message = self.shellwidget.load_data(self.filename, ext)
error_message = self.shellwidget.load_data(self.filename, extension)
QApplication.restoreOverrideCursor()
QApplication.processEvents()

Expand All @@ -245,8 +245,10 @@ def save_data(self):
filename = self.filename
if filename is None:
filename = getcwd_or_home()
ext = osp.splitext(filename)[1].lower()
if not ext:
extension = osp.splitext(filename)[1].lower()
if not extension:
# Needed to prevent trying to save a data file without extension
# See spyder-ide/spyder#7196
filename = filename + '.spydata'
filename, _selfilter = getsavefilename(self, _("Save data"),
filename,
Expand Down

0 comments on commit 31136ab

Please sign in to comment.