Repository: spyder-ide/spyder

Issue:
TypeError when disabling completion providers
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Tools > Preferences > Competions and linting > General
Unmarked "Notify me wehn Kite can Provide ..." and "Enable Kite provider"
"OK"

### Traceback
```python-traceback
Traceback (most recent call last):
  File "/home/freeman/.local/lib/python3.8/site-packages/spyder/plugins/preferences/widgets/configdialog.py", line 127, in accept
    configpage.apply_changes()
  File "/home/freeman/.local/lib/python3.8/site-packages/spyder/plugins/preferences/api.py", line 108, in apply_changes
    self.apply_callback()
  File "/home/freeman/.local/lib/python3.8/site-packages/spyder/plugins/preferences/api.py", line 140, in <lambda>
    self._apply_settings_tabs(self.changed_options))
  File "/home/freeman/.local/lib/python3.8/site-packages/spyder/plugins/preferences/api.py", line 168, in _apply_settings_tabs
    self.apply_settings(options)
  File "/home/freeman/.local/lib/python3.8/site-packages/spyder/api/preferences.py", line 105, in wrapper
    func(opts)
  File "/home/freeman/.local/lib/python3.8/site-packages/spyder/api/plugins/new_api.py", line 550, in apply_conf
    self.after_configuration_update(list(options_set))
  File "/home/freeman/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 403, in after_configuration_update
    self.unregister_statusbar(provider_name)
  File "/home/freeman/.local/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 477, in unregister_statusbar
    if id_ in container.statusbar_widgets[id_]:
TypeError: argument of type 'KiteStatusWidget' is not iterable
```

## Versions

* Spyder version: 5.2.2 
* Python version: 3.8.10
* Qt version: 5.12.10
* PyQt5 version: 5.12.3
* Operating System: Linux 5.11.0-46-generic

### Dependencies

```
# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  3.0.4 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0;<8.0.0        :  7.31.1 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  4.4.0 (OK)
keyring >=17.0.0              :  18.0.1 (OK)
nbconvert >=4.0               :  6.4.1 (OK)
numpydoc >=0.6.0              :  1.2 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.6.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.9.0 (OK)
pygments >=2.0                :  2.11.2 (OK)
pylint >=2.5.0                :  2.12.2 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.3.2;<1.4.0          :  1.3.3 (OK)
pylsp_black >=1.0.0           :  1.0.1 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.1.1 (OK)
qtconsole >=5.2.1;<5.3.0      :  5.2.2 (OK)
qtpy >=1.5.0                  :  2.0.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  60.5.0 (OK)
sphinx >=0.6.6                :  4.4.0 (OK)
spyder_kernels >=2.2.1;<2.3.0 :  2.2.1 (OK)
textdistance >=4.2.0          :  4.2.2 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.6 (OK)
xdg >=0.26                    :  0.26 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  None (NOK)
matplotlib >=2.0.0            :  None (NOK)
numpy >=1.7                   :  None (NOK)
pandas >=1.1.1                :  None (NOK)
scipy >=0.17.0                :  None (NOK)
sympy >=0.7.3                 :  None (NOK)
```



Discussion:
Hey @marleup, thanks for reporting. I can confirm this bug.

We'll try to fix it in our next version (5.3.0), to be released in a couple of months.

Resolving patch:
diff --git a/spyder/plugins/completion/plugin.py b/spyder/plugins/completion/plugin.py
--- a/spyder/plugins/completion/plugin.py
+++ b/spyder/plugins/completion/plugin.py
@@ -474,11 +474,11 @@ def register_statusbar_widget(self, provider_name, plugin_loaded=True):
             provider.STATUS_BAR_CLASSES, provider_name)
         if plugin_loaded:
             for id_ in widgets_ids:
-                # Validation to check for status bar registration before
-                # adding a widget.
-                # See spyder-ide/spyder#16977
-                if id_ not in container.statusbar_widgets:
-                    current_widget = container.statusbar_widgets[id_]
+                current_widget = container.statusbar_widgets[id_]
+                # Validation to check for status bar registration before trying
+                # to add a widget.
+                # See spyder-ide/spyder#16997
+                if id_ not in self.statusbar.get_status_widgets():
                     self.statusbar.add_status_widget(current_widget)
 
     def unregister_statusbar(self, provider_name):
@@ -496,8 +496,8 @@ def unregister_statusbar(self, provider_name):
         for id_ in provider_keys:
             # Validation to check for status bar registration before trying
             # to remove a widget.
-            # See spyder-ide/spyder#16977
-            if id_ in container.statusbar_widgets[id_]:
+            # See spyder-ide/spyder#16997
+            if id_ in container.statusbar_widgets:
                 self.get_container().remove_statusbar_widget(id_)
                 self.statusbar.remove_status_widget(id_)
 


Test patch: