Repository: spyder-ide/spyder

Issue:
Editing in 4.2.2 causes issue popup
## Problem Description

Editing some code in 4.2.2 in Windows (launched from Powershell)
The editor suddenly pops up a window saying an issue has occurred, but no error is reported
The internal console shows errors

### What steps reproduce the problem?

1.  In the editor, I was converting some code to a function:
```
analyze_feature_importance(baseline_DNN_model,
                           np.array(train_X.drop(columns =
                                                 exclude_vars)),
                                     np.array(train_Y),
                                     imp_quantile,
                                     1, 1)
def analyze_feature_importance(model,
                               X_data, Y_data, keep_list,
                               quantile,
                               repeats, n_jobs):
    start = ts(ms = True, real = True)
    importances = permutation_importance(baseline_DNN_model,
                                         np.array(train_X.drop(columns =
                                                               exclude_vars)),
                                         np.array(train_Y),
                                         n_repeats = 1,
                                         random_state = 42,
                                         n_jobs = 1)
<more code>
```
The code beginning with def was the start of converting a block of code to a function
The code just above was defining what the call would be in the main code
The linting or other features seemed to get upset
2. The popup as shown here appears:
![image](https://user-images.githubusercontent.com/30508983/109438678-398f5380-79e8-11eb-8063-f7d3d102f971.png)

3. Closing it only fixes it for a moment, then it reappears
4. Exiting, reinstalling 4.2.1, and using the same code fixed the problem

### What is the expected output? What do you see instead?
I should be able to just edit

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback (from internal console, not main console)
>>> --- Logging error ---
Traceback (most recent call last):
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1927, in update_and_merge_folding
    current_tree, root = merge_folding(
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 177, in merge_folding
    deleted_entry_i.delete()
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 39, in delete
    self.parent.remove_node(self)
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 57, in remove_node
    self.children.pop(node.index)
IndexError: pop index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1081, in emit
    msg = self.format(record)
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 925, in format
    return fmt.format(record)
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 664, in format
    record.message = record.getMessage()
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 369, in getMessage
    msg = msg % self.args
ValueError: incomplete format
Call stack:
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1938, in update_and_merge_folding
    self.log_lsp_handle_errors("Error when processing folding")
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1137, in log_lsp_handle_errors
    logger.error('%', 1, stack_info=True)
Message: '%'
Arguments: (1,)
--- Logging error ---
Traceback (most recent call last):
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1927, in update_and_merge_folding
    current_tree, root = merge_folding(
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 169, in merge_folding
    deleted_entry_i.delete()
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 39, in delete
    self.parent.remove_node(self)
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 57, in remove_node
    self.children.pop(node.index)
IndexError: pop index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1081, in emit
    msg = self.format(record)
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 925, in format
    return fmt.format(record)
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 664, in format
    record.message = record.getMessage()
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 369, in getMessage
    msg = msg % self.args
ValueError: incomplete format
Call stack:
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1938, in update_and_merge_folding
    self.log_lsp_handle_errors("Error when processing folding")
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1137, in log_lsp_handle_errors
    logger.error('%', 1, stack_info=True)
Message: '%'
Arguments: (1,)
--- Logging error ---
Traceback (most recent call last):
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1927, in update_and_merge_folding
    current_tree, root = merge_folding(
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 169, in merge_folding
    deleted_entry_i.delete()
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 39, in delete
    self.parent.remove_node(self)
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 57, in remove_node
    self.children.pop(node.index)
IndexError: pop index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 1081, in emit
    msg = self.format(record)
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 925, in format
    return fmt.format(record)
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 664, in format
    record.message = record.getMessage()
  File "c:\users\bbate\appdata\local\programs\python\python38\lib\logging\__init__.py", line 369, in getMessage
    msg = msg % self.args
ValueError: incomplete format
Call stack:
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1938, in update_and_merge_folding
    self.log_lsp_handle_errors("Error when processing folding")
  File "c:\users\bbate\envs\keras-gpu-7-py-3.8\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 1137, in log_lsp_handle_errors
    logger.error('%', 1, stack_info=True)
Message: '%'
Arguments: (1,)
```

## Versions
* Spyder version: 4.2.1 None
* Python version: 3.8.8 64-bit
* Qt version: 5.12.10
* PyQt5 version: 5.12.3
* Operating System: Windows 10

### Dependencies
```

# Mandatory:
atomicwrites >=1.2.0            :  1.4.0 (OK)
chardet >=2.0.0                 :  3.0.4 (OK)
cloudpickle >=0.5.0             :  1.6.0 (OK)
diff_match_patch >=20181111     :  20200713 (OK)
intervaltree >=3.0.2            :  3.1.0 (OK)
IPython >=7.6.0                 :  7.20.0 (OK)
jedi =0.17.2                    :  0.17.2 (OK)
jsonschema >=3.2.0              :  3.2.0 (OK)
keyring >=17.0.0                :  22.0.1 (OK)
nbconvert >=4.0                 :  6.0.7 (OK)
numpydoc >=0.6.0                :  1.1.0 (OK)
paramiko >=2.4.0                :  2.7.2 (OK)
parso =0.7.0                    :  0.7.0 (OK)
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.8.0 (OK)
pylint >=1.0                    :  2.7.0 (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.0             :  0.3.2 (OK)
qdarkstyle >=2.8                :  2.8.1 (OK)
qtawesome >=0.5.7               :  1.0.2 (OK)
qtconsole >=5.0.1               :  5.0.2 (OK)
qtpy >=1.5.0                    :  1.9.0 (OK)
setuptools >=39.0.0             :  52.0.0 (OK)
sphinx >=0.6.6                  :  3.5.1 (OK)
spyder_kernels >=1.10.1;<1.11.0 :  1.10.2 (OK)
textdistance >=4.2.0            :  4.2.1 (OK)
three_merge >=0.1.1             :  0.1.1 (OK)
watchdog >=0.10.3               :  0.10.3 (OK)
zmq >=17                        :  22.0.3 (OK)

# Optional:
cython >=0.21                   :  0.29.14 (OK)
matplotlib >=2.0.0              :  3.3.4 (OK)
numpy >=1.7                     :  1.19.5 (OK)
pandas >=1.1.1                  :  1.2.2 (OK)
scipy >=0.17.0                  :  1.6.1 (OK)
sympy >=0.7.3                   :  None (NOK)

```



Discussion:
Hey @eafpres, thanks for reporting. @andfoy will take a look at it and we'll fix it in our 4.2.3 version, to be released in a couple of days.
~~Also, @ccordoba12 , assuming @eafpres used the automatic error reporting in Spyder 4.2.2, it seems the version number is being incorrectly reported as 4.2.1 and with the commit hash (as `None`). @eafpres , could you verify how you installed Spyder (installer, Anaconda, pip, etc) and what you see displayed as the version in the `About` dialog box (under help)? Thanks!~~ Seems like this wasn't due to Spyder after all
"it seems the version number is being incorrectly reported as 4.2.1 and with the commit hash "

My bad; I saved the screenshot and the internal console message but then reinstalled 4.2.1 before submitting, so the version I copied is wrong.  The internal console information is from 4.2.2.

Sorry

"could you verify how you installed Spyder"
So this particular installation was built using venv in Powershell and only using pip from the ground up.  Honestly, I'm giving up on Anaconda as their new polices suck and there are too many things they are keeping up with, so I always end up with hybrid environments.  So I've begin building new stuff in PS using pip and not using Anaconda or minconda at all.

So, I had 4.2.1 in this env, and I simply did pip install spyder==4.2.2
When I ran into issues, I just did pip install spyder==4.2.1


Thanks for clarifying, @eafpres . In case you're unaware, we now offer pre-built, standalone Windows and Mac installers that don't rely on Anaconda or have any restrictions on use (and have always offered packages for various Linux distros) and have all the standard scientific packages built right in, which you can freely use with any Python environment (built-in Python, venv, Anaconda env, etc) that you wish.

Also, unless something has changed very recently (last month or two), using Conda-Forge with Miniconda does not have the same commercial use restrictions as the Anaconda distribution proper, and there's also [Miniforge](https://github.com/conda-forge/miniforge) which is Miniconda with Conda-Forge set as default and several extras (so you don't run into the "hybrid environments" (mixed channels) issue you mentioned. See the [question in our FAQ](https://docs.spyder-ide.org/current/faq.html#anaconda-license) for more details on that.

Of course, you're still welcome to build Spyder yourself and use it with `pip`, and we still support it isofar as fixing any bugs on Spyder's end (as this appears to be); just be aware that its recommended for experienced users who are comfortable fixing machine- and environment-specific issues themselves, which you certainly seem to be. Thanks!
Thanks for the information.  Regarding the installer, I also build different envs. for different Python versions, would that still be feasible?
Yes; since Spyder 3.3.0 from a couple years back, our [recommend approach](https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder#the-modular-approach) is to simply keep one copy of Spyder (unless you want to use multiple different verisons of the IDE itself, e.g. Spyder 4, Spyder 5, etc, or for testing), and use it with all your different working environments (conda envs, venvs, Python installs, remote machines, etc) so long as they have the `spyder_kernels` package installed so Spyder can work with them.

The version of the Python runtime and packages powering Spyder itself is mostly transparent to the user, except for potentially a few corner cases; it works just fine with different Python minor versions, and at least in the recent past when we still supported Python 2, it even still worked with Python 2 consoles in a Python 3 Spyder (it might still now, though its not guaranteed; the last version with official Python 2 support was 4.1.6, IIRC; the 4.2 series officially dropped Py2 compat and support is fully removed in the forthcoming Spyder 5).

Resolving patch:
diff --git a/spyder/plugins/editor/panels/utils.py b/spyder/plugins/editor/panels/utils.py
--- a/spyder/plugins/editor/panels/utils.py
+++ b/spyder/plugins/editor/panels/utils.py
@@ -54,7 +54,10 @@ def remove_node(self, node):
         for child in self.children[node.index + 1:]:
             child.index -= 1
 
-        self.children.pop(node.index)
+        try:
+            self.children.pop(node.index)
+        except IndexError:
+            pass
         for idx, next_idx in zip(self.children, self.children[1:]):
             assert idx.index < next_idx.index
 


Test patch: