Repository: spyder-ide/spyder

Issue:
DeprecationWarning: ShellWidget._syntax_style_changed is deprecated in traitlets 4.1: use @observe and @unobserve instead
I received the following warning when running the test suite:

```
spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_banners
  <<<PACKAGEDIR>>>/spyder/plugins/ipythonconsole/widgets/shell.py:789: DeprecationWarning: ShellWidget._syntax_style_changed is deprecated in traitlets 4.1: use @observe and @unobserve instead.
    def _syntax_style_changed(self):

```


Discussion:
Hi @juliangilbey,

Did you installed all the dependencies for the test suite?
Yes I have, at least as far as I know; and this does not appear to be a dependency warning or error.  I have traitlets 5.0.5 installed.

I don't know enough about traitlets or what magic it does to properly diagnose this issue.  But spyder/plugins/ipythonconsole/plugin.py imports from traitlets, which presumably has an impact on lots of things.  The particular code in traitlets.py that raises this warning is in the function `_notify_observers` and reads:

```python
        # Now static ones
        magic_name = '_%s_changed' % name
        if event.type == "change" and hasattr(self, magic_name):
            class_value = getattr(self.__class__, magic_name)
            if not isinstance(class_value, ObserveHandler):
                _deprecated_method(class_value, self.__class__, magic_name,
                    "use @observe and @unobserve instead.")
```
So it seems that the name of this function, `_syntax_style_changed` is triggering this traitlets warning: if the name of the function is designed to invoke a traitlets behaviour, then it's not been correctly configured or something like that, and if it's not, then the name of the function should be changed.

But I may be talking nonsense.
In my environment I have trailets version 5.0.5, can you update that dependency to see if this fixes the warning?
I too have traitlets version 5.0.5.
FYI: I'm still getting this warning when running the tests in spyder 5.2.0:
```
spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py::test_conda_env_activation
  /home/jdg/debian/spyder-packages/spyder/build-area/spyder-5.2.0+dfsg1/spyder/plugins/ipythonconsole/widgets/shell.py:931: DeprecationWarning: ShellWidget._syntax_style_changed is deprecated in traitlets 4.1: use @observe and @unobserve instead.
    def _syntax_style_changed(self):
```
Maybe the reimplementation over the Spyder side of `_syntax_style_changed` (originally defined at QtConsole: https://github.com/jupyter/qtconsole/blob/fa1a7f898e7d402ac9bb64a652db5dc509e1f649/qtconsole/jupyter_widget.py#L594-L595) also needs to be decorated with `@observe('syntax_style')` (and checking seems like over the Spyder side the `kwarg` is missing). Could you check if that helps @juliangilbey ? Thanks!
Yes, that fixed it - well done!  I'll make a PR for this.

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole/widgets/shell.py b/spyder/plugins/ipythonconsole/widgets/shell.py
--- a/spyder/plugins/ipythonconsole/widgets/shell.py
+++ b/spyder/plugins/ipythonconsole/widgets/shell.py
@@ -19,6 +19,7 @@
 from qtpy.QtCore import Signal, QThread
 from qtpy.QtWidgets import QMessageBox
 from qtpy import QtCore, QtWidgets, QtGui
+from traitlets import observe
 
 # Local imports
 from spyder.config.base import (
@@ -933,7 +934,8 @@ def _handle_kernel_restarted(self, *args, **kwargs):
         super(ShellWidget, self)._handle_kernel_restarted(*args, **kwargs)
         self.sig_kernel_restarted.emit()
 
-    def _syntax_style_changed(self):
+    @observe('syntax_style')
+    def _syntax_style_changed(self, changed=None):
         """Refresh the highlighting with the current syntax style by class."""
         if self._highlighter is None:
             # ignore premature calls


Test patch: