Repository: spyder-ide/spyder
Pull request: PR: Fix args/kwargs handling in the call_all_editorstacks signature to update completion related options for the Editor
<!--- Make sure to read the Contributing Guidelines:                   --->
<!--- https://github.com/spyder-ide/spyder/blob/master/CONTRIBUTING.md --->
<!--- and follow PEP 8, PEP 257 and Spyder's code style:               --->
<!--- https://github.com/spyder-ide/spyder/wiki/Dev:-Coding-Style      --->

## Description of Changes


* [ ] Wrote at least one-line docstrings (for any new functions)
* [ ] Added unit test(s) covering the changes (if testable)
<!--- Remember that an image/animation is worth a thousand words! --->
* [ ] Included a screenshot or animation (if affecting the UI, see [Licecap](https://www.cockos.com/licecap/))


<!--- Explain what you've done and why --->

Config updates in the completion manager for the providers were being wrapped inside a tuple


### Issue(s) Resolved

<!--- List the issue(s) below, in the form "Fixes #1234"; one per line --->

Fixes #15324


### Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the [Developer Certificate of Origin](https://developercertificate.org)
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

<!--- TYPE YOUR USER/NAME AFTER THE FOLLOWING: --->
I certify the above statement is true and correct: dalthviz

<!--- Thanks for your help making Spyder better for everyone! --->


Problem statement:
TypeError when using kite_tutorial
## Description

### What steps will reproduce the problem?

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

follow instructions in kite_tutorial.py

just type a in line 84 to try autocompletion fwhen  importing matplotlib

boom


### Traceback
```python-traceback
Traceback (most recent call last):
  File "/home/explore/miniconda3/envs/minecraft/lib/python3.6/site-packages/spyder/plugins/editor/widgets/codeeditor.py", line 4490, in _handle_completions
    if (len(text) >= self.automatic_completions_after_chars
TypeError: '>=' not supported between instances of 'int' and 'tuple'
```

## Versions

* Spyder version: 5.0.0 
* Python version: 3.6.13
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Linux 5.4.0-72-generic

### 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.2 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  7.16.1 (OK)
jedi =0.17.2                  :  0.17.2 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  22.3.0 (OK)
nbconvert >=4.0               :  6.0.7 (OK)
numpydoc >=0.6.0              :  1.1.0 (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.1 (OK)
pylint >=1.0                  :  2.7.4 (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.3.2 (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=0.5.7             :  1.0.2 (OK)
qtconsole >=5.0.3             :  5.0.3 (OK)
qtpy >=1.5.0                  :  1.9.0 (OK)
rtree >=0.8.3                 :  0.9.7 (OK)
setuptools >=39.0.0           :  52.0.0.post20210125 (OK)
sphinx >=0.6.6                :  3.5.3 (OK)
spyder_kernels >=2.0.1;<2.1.0 :  2.0.1 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3;<2.0.0      :  1.0.2 (OK)
xdg >=0.26                    :  0.27 (OK)
zmq >=17                      :  20.0.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)
```

Hints from issue discussion:
Hey @castorfou. thanks for reporting. We'll take a look at this problem.

@dalthviz, could you take a look at this? Thanks!
@ccordoba12 @castorfou I was able to replicate this but first I had to change the preferences to enable autocompletion results after just 1 character (the default is 3 I think):

![auto](https://user-images.githubusercontent.com/16781833/115279858-815c6c80-a147-11eb-8618-f1663b288a18.gif)


Note: The issue is actually caused not for an specific value but because of the change of the value. When changing it, it causes the `self.automatic_completions_after_chars` to become a tuple instead of just updating is number value (the tuple has the actual updated value inside). Strangely, after a Spyder restart the value is set properly

Commit message: Completion: Change signal emit to not put changed values as a tuple

Patch to review:
diff --git a/spyder/plugins/completion/plugin.py b/spyder/plugins/completion/plugin.py
index 6b52921f314..d32a96dcf3f 100644
--- a/spyder/plugins/completion/plugin.py
+++ b/spyder/plugins/completion/plugin.py
@@ -367,7 +367,7 @@ def after_configuration_update(self, options: List[Union[tuple, str]]):
             if opt in options:
                 opt_value = self.get_conf(opt, section=sec)
                 self.sig_editor_rpc.emit('call_all_editorstacks',
-                                         (method_name, (opt_value,)),
+                                         (method_name, opt_value,),
                                          {})
 
         # Update entries in the source menu


Code review comments:
diff_hunk: @@ -367,7 +367,7 @@ def after_configuration_update(self, options: List[Union[tuple, str]]):
             if opt in options:
                 opt_value = self.get_conf(opt, section=sec)
                 self.sig_editor_rpc.emit('call_all_editorstacks',
-                                         (method_name, (opt_value,)),
+                                         (method_name, opt_value,),
path: spyder/plugins/completion/plugin.py
text: @user1:
@author, did you test that this change works for all other `editor_method_sec_opts` items?

@user1:
I mean, I say it because perhaps it breaks applying other options listed there.

@author:
@user1 no, I was hoping @user2 could tell me if some setter there needs the tuple but then I will check :+1:

@user2:
This should be a tuple, due to the signature of this method: https://github.com/spyder-ide/spyder/blob/5c8cca33fe2cc012efdffe2c57dcf8a1143f3386/spyder/plugins/editor/plugin.py#L408

@user2:
Since the signal is only used to set options, maybe we could simplify it to consider a single argument?

@author:
From what I see and tested seems to work. Actually, seems like other options were using the truthy value of the tuple (so even if you uncheck them they didn't disable)

@author:
Just in case, checking a little bit more, seems like the tuple could be for the `edge_line_columns` however the panel handles non-tuple values too. The type of the values for the setters options are:

* `enable_code_snippets`: bool
* `enable_hover_hints`: bool
* `format_on_save`: bool
* `automatic_completions`: bool
* `completions_hint`: bool
* `completions_hint_after_ms`: int 
* `underline_errors`: bool
* `automatic_completions_after_chars`: int
* `automatic_completions_after_ms`: int
* `pycodestyle/max_line_length`: tuple
* `edge_line`: bool 

@author:
@user2 I didn't see your message above but I think I now know were the actual issue is :+1: Edit: Or maybe not 🤔 

@author:
I think there is something strange happening when passing the `args` and `kwargs` currently that is causing that they arrive to the setter methods still as a tuple (instead of being expanded when calling the corresponding setter)