Spyder: Renaming a python file in the file explorer causes an error

Created on 19 Jan 2020  路  7Comments  路  Source: spyder-ide/spyder

Description

What steps will reproduce the problem?

Had a "mobilenetv2.py" file. Renamed it via rightclick rename procedure. Typed new file name as "MobileNetV2.py". Spyder asks "do you want to rename and replace the file". Accepted --> Crash --> Send the bug--> Profit!

Traceback

  File "C:\Users\Tulpar\Anaconda3\lib\site-packages\spyder\plugins\editor\plugin.py", line 2108, in renamed
    filename, to_text_string(dest))
  File "C:\Users\Tulpar\Anaconda3\lib\site-packages\spyder\plugins\editor\utils\autosave.py", line 385, in file_renamed
    old_hash = self.file_hashes[old_name]
KeyError: 'C:\\ferfiles\\mobilenetv2.py'

Versions

  • Spyder version: 4.0.1
  • Python version: 3.7.3
  • Qt version: 5.9.6
  • PyQt5 version: 5.9.2
  • Operating System: Windows 10

Dependencies

atomicwrites >=1.2.0         :  1.3.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.2.2 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.11.1 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
numpydoc >=0.6.0             :  0.9.2 (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.6.7 (OK)
pygments >=2.0               :  2.5.2 (OK)
pylint >=0.25                :  2.4.4 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.2 (OK)
zmq >=17                     :  18.1.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
sphinx >=0.6.6               :  2.3.1 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.8.1 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  0.29.14 (OK)
matplotlib >=2.0.0           :  3.1.1 (OK)
numpy >=1.7                  :  1.17.4 (OK)
pandas >=0.13.1              :  0.25.3 (OK)
scipy >=0.17.0               :  1.3.2 (OK)
sympy >=0.7.3                :  1.5 (OK)
Editor Bug v4.1.0

Most helpful comment

File Explorer, in particular line 904-908

After looking at it in more depth, I am quite certain that those lines need to be changed because I discovered a user-visible bug which can be reproduced as follows:

  1. Make a directory with files foo and foobar (the important thing is that the first name is a prefix of the second name).
  2. Open both files in the editor.
  3. In the file explorer, rename foo to ham
  4. Note that in the editor, the tab foo is also renamed to ham (as expected). However, the tab foobar is erroneously renamed to hambar (which leads the editor to complain that that file does not exist).

I am preparing a PR to fix this. The fix makes the issue originally reported here much more prominent, so I will also include a fix for that.

All 7 comments

I think file names on Windows are case insensitve, so there's no difference between mobilenetv2.py and MobileNetV2.py, and that's why the error appears.

@jitseniesen, could you take a look at this one?

I think file names on Windows are case insensitve, so there's no difference between mobilenetv2.py and MobileNetV2.py, and that's why the error appears.

Well spotted!

@jitseniesen, could you take a look at this one?

Will do.

I am trying to understand the traceback, which led me to the File Explorer, in particular line 904-908:

https://github.com/spyder-ide/spyder/blob/6b8c3f1dae50be1c49ecbe3424cc22965d9f9a44/spyder/plugins/explorer/widgets/explorer.py#L904-L908

I wonder whether the second line above should have path instead of fname, so that it reads

if osp.isfile(path):

After the rename_file, the file fname is renamed to path, so we should call osp.file on the new name.

Can somebody please check whether that makes sense? I am hesitant to touch code that I don't really understand, and there don't seem to be any adverse effects at the moment.

Can somebody please check whether that makes sense?

@goanpeca, please help @jitseniesen with that.

Will do!

File Explorer, in particular line 904-908

After looking at it in more depth, I am quite certain that those lines need to be changed because I discovered a user-visible bug which can be reproduced as follows:

  1. Make a directory with files foo and foobar (the important thing is that the first name is a prefix of the second name).
  2. Open both files in the editor.
  3. In the file explorer, rename foo to ham
  4. Note that in the editor, the tab foo is also renamed to ham (as expected). However, the tab foobar is erroneously renamed to hambar (which leads the editor to complain that that file does not exist).

I am preparing a PR to fix this. The fix makes the issue originally reported here much more prominent, so I will also include a fix for that.

Thanks @jitseniesen !

Was this page helpful?
0 / 5 - 0 ratings