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

KeyError self.editor_ids[self.current_editor] #15668

Closed
bnavigator opened this issue May 21, 2021 · 9 comments
Closed

KeyError self.editor_ids[self.current_editor] #15668

bnavigator opened this issue May 21, 2021 · 9 comments
Assignees
Labels

Comments

@bnavigator
Copy link
Contributor

@bnavigator , it actually looks like your first error is

editor_id = self.editor_ids[self.current_editor]
KeyError: <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f0efd7ea280>

which means that self.current_editor returns an OutlineExplorerProxyEditor object instead of a string object. Could this be related to PyQt5 >= 5.13?

Originally posted by @mrclary in #14803 (comment)

@bnavigator
Copy link
Contributor Author

Is self.current_editor supposed to return a string here? Because to me, it looks like you assign and retrieve an editor object:

@property
def current_editor(self):
"""Get current editor."""
return self._current_editor
@current_editor.setter
def current_editor(self, value):
"""Set current editor and connect the necessary signals."""
if self._current_editor == value:
return
# Disconnect previous editor
self.connect_current_editor(False)
self._current_editor = value
# Connect new editor
self.connect_current_editor(True)

def set_current_editor(self, editor, update):
"""Bind editor instance"""
editor_id = editor.get_id()
# Don't fail if editor doesn't exist anymore. This
# happens when switching projects.
try:
item = self.editor_items[editor_id].node
except KeyError:
return
if not self.freeze:
self.scrollToItem(item)
self.root_item_selected(item)
self.__hide_or_show_root_items(item)
if update:
self.save_expanded_state()
self.restore_expanded_state()
self.current_editor = editor

@mrclary
Copy link
Contributor

mrclary commented May 21, 2021

I inserted some print statements at line 412 and ran bootstrap from a pyenv environment with PyQt5=5.15.4

    @Slot()
    def go_to_cursor_position(self):
        if self.current_editor is not None:
            print(f'TEST: self.current_editor = {self.current_editor}')
            print(f'TEST: self.editor_ids = {self.editor_ids}')
            editor_id = self.editor_ids[self.current_editor]

with the following results

(spy-build) >> python bootstrap.py
Executing Spyder from source checkout
*. Patched sys.path with /Users/rclary/Documents/Python/spyder
*. Patched sys.path with /Users/rclary/Documents/Python/spyder/external-deps/spyder-kernels
*. Patched sys.path with /Users/rclary/Documents/Python/spyder/external-deps/qdarkstyle
*. Patched sys.path with /Users/rclary/Documents/Python/spyder/external-deps/python-language-server
*. Removing previous PyLS local installation.
*. Installing PyLS locally
*. Declaring completion providers
*. PyQt5 is detected, selecting
*. Imported Spyder 5.1.0.dev0 - Revision 65294a8b8, Branch: constrain-watchdog
    [Python 3.9.4 64bits, Qt 5.15.2, PyQt5 5.15.4 on Darwin]
*. Running Spyder
Bootstrap completed in 00:00:01.2356
No QCoreApplication instance found. Application patches not applied. You have to call load_stylesheet function after instantiation of QApplication to take effect. 
The available OpenGL surface format was either not version 3.2 or higher or not a Core Profile.
Chromium on macOS will fall back to software rendering in this case.
Hardware acceleration and features such as WebGL will not be available.
Populating font family aliases took 177 ms. Replace uses of missing font family "Quattrocento Sans" with one that exists to avoid this cost. 
TEST: self.current_editor = <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x158df7b80>
TEST: self.editor_ids = {<spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x158df7b80>: 5782023904}

That was upon startup. I was incorrect about my assumption that it was looking for a string object. It appears that the dictionary is using unique objects as keys.
Nevertheless, upon switching projects once, no prints are encountered, so go_to_cursor_position is not accessed.
Upon switching back to the orignal project, again no prints are encountered, but I get the error reported in #14803

ERROR:fsevents:Unhandled exception in FSEventsEmitter
Traceback (most recent call last):
  File "/Users/rclary/.pyenv/versions/3.9.4/envs/spy-build/lib/python3.9/site-packages/watchdog/observers/fsevents.py", line 310, in run
    _fsevents.add_watch(self, self.watch, self.events_callback, self.pathnames)
RuntimeError: Cannot add watch <ObservedWatch: path=/Users/rclary/Documents/Python/c2w_psp, is_recursive=True> - it is already scheduled

Can you run with some print statements to see under what circumstances there is a KeyError?

@juanis2112 juanis2112 self-assigned this May 21, 2021
@bnavigator
Copy link
Contributor Author

Same print statements as yours:

console calling spyder:

[ben@skylab:~/tmp]% spyder                                                                                                                                                              [0]
No QCoreApplication instance found. Application patches not applied. You have to call load_stylesheet function after instantiation of QApplication to take effect. 
TEST: self.current_editor = <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88a00c29d0>
TEST: self.editor_ids = {<spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88a00c29d0>: 140224778013568}
TEST: self.current_editor = <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88a00e88b0>
TEST: self.editor_ids = {<spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88a00c29d0>: 140224778013568, <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88a00e88b0>: 140224778013568}

Then switching projects, upon switching back there appears the "Issue reporter" with different contents for editor_ids:

TEST: self.editor_ids = {<spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88d1725b80>: 140225614856688, <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88d0e914c0>: 140225614856688, <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88d0e83af0>: 140225614664752, <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88d0e8e430>: 140225614664752}
TEST: self.current_editor = <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88d1725b80>
TEST: self.editor_ids = {<spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88d0e914c0>: 140225614856688, <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88d0e83af0>: 140225614664752, <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88d0e8e430>: 140225614664752}
Traceback (most recent call last):
  File "/home/ben/tmp/spydertest/spyder/plugins/editor/widgets/editor.py", line 2177, in focus_changed
    self.refresh()
  File "/home/ben/tmp/spydertest/spyder/plugins/editor/widgets/editor.py", line 2320, in refresh
    self._refresh_outlineexplorer(index, update=False)
  File "/home/ben/tmp/spydertest/spyder/plugins/editor/widgets/editor.py", line 2190, in _refresh_outlineexplorer
    oe.set_current_editor(finfo.editor.oe_proxy,
  File "/home/ben/tmp/spydertest/spyder/plugins/outlineexplorer/widgets.py", line 1014, in set_current_editor
    self.treewidget.set_current_editor(editor, update)
  File "/home/ben/tmp/spydertest/spyder/plugins/outlineexplorer/widgets.py", line 490, in set_current_editor
    self.current_editor = editor
  File "/home/ben/tmp/spydertest/spyder/plugins/outlineexplorer/widgets.py", line 344, in current_editor
    self.connect_current_editor(True)
  File "/home/ben/tmp/spydertest/spyder/plugins/outlineexplorer/widgets.py", line 455, in connect_current_editor
    self.do_follow_cursor()
  File "/home/ben/tmp/spydertest/spyder/plugins/outlineexplorer/widgets.py", line 407, in do_follow_cursor
    self.go_to_cursor_position()
  File "/home/ben/tmp/spydertest/spyder/plugins/outlineexplorer/widgets.py", line 414, in go_to_cursor_position
    editor_id = self.editor_ids[self.current_editor]
KeyError: <spyder.plugins.outlineexplorer.editor.OutlineExplorerProxyEditor object at 0x7f88d1725b80>
Traceback (most recent call last):
  File "/home/ben/tmp/spydertest/spyder/plugins/editor/panels/debugger.py", line 89, in paintEvent
    painter.fillRect(event.rect(), self.editor.sideareas_color)
TypeError: arguments did not match any overloaded call:
  fillRect(self, QRectF, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 2 has unexpected type 'NoneType'
  fillRect(self, int, int, int, int, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, QRectF, Union[QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Union[QColor, Qt.GlobalColor, QGradient]): argument 2 has unexpected type 'NoneType'
  fillRect(self, int, int, int, int, Union[QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, int, int, int, int, Qt.GlobalColor): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Qt.GlobalColor): argument 2 has unexpected type 'NoneType'
  fillRect(self, QRectF, Qt.GlobalColor): argument 1 has unexpected type 'QRect'
  fillRect(self, int, int, int, int, Qt.BrushStyle): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Qt.BrushStyle): argument 2 has unexpected type 'NoneType'
  fillRect(self, QRectF, Qt.BrushStyle): argument 1 has unexpected type 'QRect'
  fillRect(self, int, int, int, int, QGradient.Preset): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, QGradient.Preset): argument 2 has unexpected type 'NoneType'
  fillRect(self, QRectF, QGradient.Preset): argument 1 has unexpected type 'QRect'
Traceback (most recent call last):
  File "/home/ben/tmp/spydertest/spyder/plugins/editor/panels/linenumber.py", line 68, in paintEvent
    painter.fillRect(event.rect(), self.editor.sideareas_color)
TypeError: arguments did not match any overloaded call:
  fillRect(self, QRectF, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 2 has unexpected type 'NoneType'
  fillRect(self, int, int, int, int, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, QRectF, Union[QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Union[QColor, Qt.GlobalColor, QGradient]): argument 2 has unexpected type 'NoneType'
  fillRect(self, int, int, int, int, Union[QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, int, int, int, int, Qt.GlobalColor): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Qt.GlobalColor): argument 2 has unexpected type 'NoneType'
  fillRect(self, QRectF, Qt.GlobalColor): argument 1 has unexpected type 'QRect'
  fillRect(self, int, int, int, int, Qt.BrushStyle): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Qt.BrushStyle): argument 2 has unexpected type 'NoneType'
  fillRect(self, QRectF, Qt.BrushStyle): argument 1 has unexpected type 'QRect'
  fillRect(self, int, int, int, int, QGradient.Preset): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, QGradient.Preset): argument 2 has unexpected type 'NoneType'
  fillRect(self, QRectF, QGradient.Preset): argument 1 has unexpected type 'QRect'
Traceback (most recent call last):
  File "/home/ben/tmp/spydertest/spyder/plugins/editor/panels/scrollflag.py", line 183, in paintEvent
    painter.fillRect(event.rect(), self.editor.sideareas_color)
TypeError: arguments did not match any overloaded call:
  fillRect(self, QRectF, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 2 has unexpected type 'NoneType'
  fillRect(self, int, int, int, int, Union[QBrush, QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, QRectF, Union[QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Union[QColor, Qt.GlobalColor, QGradient]): argument 2 has unexpected type 'NoneType'
  fillRect(self, int, int, int, int, Union[QColor, Qt.GlobalColor, QGradient]): argument 1 has unexpected type 'QRect'
  fillRect(self, int, int, int, int, Qt.GlobalColor): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Qt.GlobalColor): argument 2 has unexpected type 'NoneType'
  fillRect(self, QRectF, Qt.GlobalColor): argument 1 has unexpected type 'QRect'
  fillRect(self, int, int, int, int, Qt.BrushStyle): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, Qt.BrushStyle): argument 2 has unexpected type 'NoneType'
  fillRect(self, QRectF, Qt.BrushStyle): argument 1 has unexpected type 'QRect'
  fillRect(self, int, int, int, int, QGradient.Preset): argument 1 has unexpected type 'QRect'
  fillRect(self, QRect, QGradient.Preset): argument 2 has unexpected type 'NoneType'
  fillRect(self, QRectF, QGradient.Preset): argument 1 has unexpected type 'QRect'

The message in the debug window starts with the editor_ids print, but the current_editor print is missing!

@bnavigator
Copy link
Contributor Author

bnavigator commented May 21, 2021

Oh, I need to have at least 2 files open in a split editor window in order to trigger the error!

@mrclary
Copy link
Contributor

mrclary commented May 21, 2021

I had a minimum of two files opened in each project.
I notice that you have 2 calls to go_to_cursor_position, while I only have one on startup. I don't see print statements when I switch projects, even after the second time; while you show the print statements and and the error on the second project switch. These are puzzling to me and don't know why.

Can you remind me of your system setup? Ubuntu, right? Can you also include your environment ($ conda list or $ pip list)?

@mrclary
Copy link
Contributor

mrclary commented May 21, 2021

Sorry, openSUSE. I don't have a VM for that, so I can't test it. I can check on Ubuntu, though.

@bnavigator
Copy link
Contributor Author

I notice that you have 2 calls to go_to_cursor_position, while I only have one on startup. I don't see print statements when I switch projects, even after the second time; while you show the print statements and and the error on the second project switch. These are puzzling to me and don't know why.

I am not sure, but I think between startup and display of the issue reporter some capture of printout kicks in.

Can you remind me of your system setup? Ubuntu, right? Can you also include your environment ($ conda list or $ pip list)?

No conda or virtual environment at all, no pip install. Plain openSUSE packages. The versions are not 100% compliant with the Spyder pins, so I can completely understand when you are not willing to put too much effort into the investigation:

Help->Dependencies...:

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  1.6.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.0.2 (OK)
IPython >=7.6.0               :  7.22.0 (OK)
jedi >=0.17.2                 :  0.18.0 (OK)  <-- unpinned
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  21.2.1 (OK)
nbconvert >=4.0               :  6.0.7 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
parso >=0.7.0                 :  0.8.1 (OK) <-- unpinned
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.7.4 (OK)
pylint >=1.0                  :  2.8.2 (OK)
pyls >=0.36.2;<1.0.0          :  0.36.2 (OK)
pyls_black >=0.4.6            :  0.4.6 (OK)
pyls_spyder >=0.3.2;<0.4.0    :  0.3.2 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.0 (OK)
qtawesome >=1.0.2             :  1.0.2 (OK)
qtconsole >=5.1.0             :  5.1.0 (OK)
qtpy >=1.5.0                  :  1.9.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=39.0.0           :  44.1.1 (OK)
sphinx >=0.6.6                :  3.5.4 (OK)
spyder_kernels >=2.0.3;<2.1.0 :  2.0.3 (OK)
textdistance >=4.2.0          :  4.2.0 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.1 (OK) <-- unpinned
xdg >=0.26                    :  0.27 (OK)
zmq >=17                      :  22.0.3 (OK)

# Optional:
cython >=0.21                 :  0.29.23 (OK)
matplotlib >=2.0.0            :  3.4.2 (OK)
numpy >=1.7                   :  1.20.2 (OK)
pandas >=1.1.1                :  1.2.4 (OK)
scipy >=0.17.0                :  1.6.3 (OK)
sympy >=0.7.3                 :  1.8 (OK)

Addtionally relevant:

When I close the outline editor panel, there is no error and trigger of issue reporter.

Even without switching projects, or the error, the contents of the outline explorer do not look right to me:

Screenshot_20210523_182150

@mrclary
Copy link
Contributor

mrclary commented May 23, 2021

Well, I would definitely recommend creating a virtual environment from which to run Spyder. You can still use any other Python environment (including your system environment) to work in (running the Console and executing code). See https://docs.spyder-ide.org/current/installation.html#new-conda-environment or https://docs.spyder-ide.org/current/installation.html#using-pip.

@bnavigator
Copy link
Contributor Author

I cannot reproduce the error anymore. None of the listed direct dependencies changed from #15668 (comment) to now.

Notable changes which could be related:

  • Python packages:
    • PyQt5.sip 12.8.1 -> 12.9.0
    • libcst 0.3.17 -> 0.3.19
    • fsspec 0.8.5 -> 2021.5.0
  • Some recompiled system libraries:
    • libX11 and libX11-xcb
    • nothing Qt related.

Well, I would definitely recommend creating a virtual environment from which to run Spyder.

That currently pulls in 538 MB of unnecessary, duplicate and outdated stuff. Most notably a complete set of precompiled Qt libraries, which don't work well in parallel with an already loaded system Qt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants