Repository: spyder-ide/spyder

Issue:
File switcher error
## Description

**What steps will reproduce the problem?**

1. 
2. 
3. 

**What is the expected output? What do you see instead?**


**Please provide any additional information below**

  File "/usr/local/lib/python3.5/dist-packages/spyder/app/mainwindow.py", line 2795, in open_fileswitcher
    self.fileswitcher.setup()
  File "/usr/local/lib/python3.5/dist-packages/spyder/widgets/fileswitcher.py", line 757, in setup
    current_path = self.current_path
  File "/usr/local/lib/python3.5/dist-packages/spyder/widgets/fileswitcher.py", line 346, in current_path
    return self.paths_by_widget[self.get_widget()]
KeyError: None



## Version and main components

* Spyder Version: 3.2.3 
* Python Version: 3.5.2
* Qt Versions: 5.9.1, PyQt5 5.9 on Linux

## Dependencies
```
pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.17.1 (OK)
numpy >=1.7      :  1.11.0 (OK)
sphinx >=0.6.6   :  1.6.4 (OK)
rope >=0.9.4     :  0.10.7 (OK)
jedi >=0.9.0     :  0.11.0 (OK)
psutil >=0.3     :  5.3.1 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  None (NOK)
cython >=0.21    :  None (NOK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.2.1 (OK)
pylint >=0.25    :  1.7.4 (OK)

```



Discussion:
@ccordoba12 I'm going to take a look at it.

@ram15565 Thanks for the report. Could you tell us a little bit more about what you were doing when the error happened?
For the record, this is not a duplicate, but this is related to Issue #5317. These two issues could probably be fixed with the same PR.
  
@ccordoba12 
This issue is hard to reproduce. So far, I've been able to reproduce it only with the spyder-notebook:

1 - open spyder
2 - go to a notebook tab using the global file switcher (<kbd>Ctrl</kbd>+<kbd>p</kbd>).
3 - close all tabs of the notebook
4 - open the global file switcher again

```python
Traceback (most recent call last):
  File "C:\Users\jsgosselin\spyder\spyder\app\mainwindow.py", line 2798, in open_fileswitcher
    self.fileswitcher.setup()
  File "C:\Users\jsgosselin\spyder\spyder\widgets\fileswitcher.py", line 757, in setup
    current_path = self.current_path
  File "C:\Users\jsgosselin\spyder\spyder\widgets\fileswitcher.py", line 346, in current_path
    return self.paths_by_widget[self.get_widget()]
KeyError: None
```

So far, I've been unable to reproduce this error with the Editor because I can't find a case when the Editor would allow to have no file opened. It always open a temp or untitled file, thus preventing this error to occur.

So what I can do is to implement a safeguard in the file switcher to handle the case when `self.get_widget()` returns `None`.
> So what I can do is to implement a safeguard in the file switcher to handle the case when self.get_widget() returns None.

Sure, I think it's the best solution. @dalthviz, what do think?
Yep I think is ok :+1: @ccordoba12, and thanks again @jnsebgosselin for all the good work in the `Fileswitcher` :)
Alright then, I'm going to work on this this weekend. Thanks for the feedback guys.
@jnsebgosselin, any updates on this one?
@ccordoba12  I'm going to work on this this week.

Resolving patch:
diff --git a/spyder/widgets/fileswitcher.py b/spyder/widgets/fileswitcher.py
--- a/spyder/widgets/fileswitcher.py
+++ b/spyder/widgets/fileswitcher.py
@@ -346,7 +346,7 @@ def icons(self):
 
     @property
     def current_path(self):
-        return self.paths_by_widget[self.get_widget()]
+        return self.paths_by_widget.get(self.get_widget(), None)
 
     @property
     def paths_by_widget(self):


Test patch: