Repository: spyder-ide/spyder

Issue:
TypeError when processing completion signatures
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Not sure if this is spyder or tqdm: I'm attempting to use the tqdm library and walrus operator to make a progress bar on a for loop, e.g.:

```python
from tqdm import tqdm
for i in (pbar := tqdm(mydict.items())):
    pbar.set_description("processing mydict")
    dosomething()
```

This error occurs immediately on typing opening parenthesis on set_description( or after tqdm(, so possibly a problem with linting or real time code checking? I do not need to run anything through the console, it occurs while typing in the Editor. Also, the line with the for loop still shows 'invalid syntax: pyflakes E'.

### Traceback
```python-traceback
Traceback (most recent call last):
  File "C:\Users\tswailes\AppData\Local\Programs\Python\Python39\lib\site-packages\spyder\plugins\completion\providers\languageserver\client.py", line 558, in on_msg_received
    handler(resp['result'], req_id)
  File "C:\Users\tswailes\AppData\Local\Programs\Python\Python39\lib\site-packages\spyder\plugins\completion\providers\languageserver\providers\document.py", line 155, in process_signature_completion
    if len(response['signatures']) > 0:
TypeError: list indices must be integers or slices, not str
```

## Versions

* Spyder version: 5.3.0 
* Python version: 3.9.0
* 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               :  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.1.0 (OK)
IPython >=7.31.1;<8.0.0       :  7.32.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.17.2 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.0.0 (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.9.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 >=2.5.0                :  2.7.2 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.4.1;<1.5.0          :  1.4.1 (OK)
pylsp_black >=1.2.0           :  1.2.1 (OK)
qdarkstyle >=3.0.2;<3.1.0     :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.2.1 (OK)
qtawesome >=1.0.2             :  1.0.2 (OK)
qtconsole >=5.3.0;<5.4.0      :  5.3.0 (OK)
qtpy >=2.0.1                  :  2.0.1 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  60.9.3 (OK)
sphinx >=0.6.6                :  3.5.2 (OK)
spyder_kernels >=2.3.0;<2.4.0 :  2.3.0 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  1.0.2 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  None (NOK)
matplotlib >=3.0.0            :  None (NOK)
numpy >=1.7                   :  1.22.2 (OK)
pandas >=1.1.1                :  1.4.1 (OK)
scipy >=0.17.0                :  1.8.0 (OK)
sympy >=0.7.3                 :  None (NOK)
```



Discussion:
Hey @TSwailes, thanks for reporting. Please update Jedi to version 0.18.1 and Parso to 0.8.3 to see if that fixes your problem.
@ccordoba12 Thank you, it seems to work with updated Jedi and Parso; the pyflakes warning no longer appears and I can't replicate the error anymore. 

Turns out Jedi 0.18.1 appeared to have a conflict with python-language-server which required jedi<0.18.0 so pip was downgrading it automatically when I reinstalled my environment; that doesn't appear to be a requirement for spyder however (?); I think it's a Microsoft thing.
I got the same error today sketching up a class with methods. Using the 5.3.0 windows installer, which has `Jedi 0.18.1` and `parso 0.8.3`. I tried to reproduce it, but it is not straight forward. Just copying the snippet where this error occurs does not reproduce the error. Even renaming a method or putting a comment on the offending line can make the error go away. The error does not occur when running Spyder in debug mode either, really strange.
A "minimal" example below that causes the crash. Code doesn't make sense, but I tried to strip the full code down as much as possible while still getting the error. Placing the cursor line `y.to_numpy()`, removing the parenthesis and opening it again causes the error.
    
    from sklearn.neighbors import KernelDensity
    
    class SomeClass:
        
        def __init__(self):
            self.bw_func = lambda x: x
    
        def fit(self, y):
            y.to_numpy()
                
            bw = self.bw_func(len(y), self.dimensions)
            kde = KernelDensity(kernel='linear', bandwidth=bw).fit(y)

![spyder_error_completion](https://user-images.githubusercontent.com/2330659/165898298-dd4f7241-5a00-498e-8de6-68cd7d09ee5b.gif)


<details>

  <summary>Dependencies</summary>

```
# Mandatory:
atomicwrites >=1.2.0                 :  1.4.0 (OK)
chardet >=2.0.0                      :  4.0.0 (OK)
cloudpickle >=0.5.0                  :  2.0.0 (OK)
cookiecutter >=1.6.0                 :  1.7.3 (OK)
diff_match_patch >=20181111          :  20200713 (OK)
intervaltree                         :  None (OK)
IPython >=7.31.1;<8.0.0              :  7.32.0 (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                     :  23.5.0 (OK)
nbconvert >=4.0                      :  6.4.5 (OK)
numpydoc >=0.6.0                     :  1.2.1 (OK)
paramiko >=2.4.0                     :  2.10.3 (OK)
parso >=0.7.0;<0.9.0                 :  0.8.3 (OK)
pexpect >=4.4.0                      :  4.8.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.13.3 (OK)
pyls_spyder >=0.4.0                  :  0.4.0 (OK)
pylsp >=1.4.1;<1.5.0                 :  1.4.1 (OK)
pylsp_black >=1.2.0                  :  1.2.0 (OK)
qdarkstyle >=3.0.2;<3.1.0            :  3.0.3 (OK)
qstylizer >=0.1.10                   :  0.2.1 (OK)
qtawesome >=1.0.2                    :  1.1.1 (OK)
qtconsole >=5.3.0;<5.4.0             :  5.3.0 (OK)
qtpy >=2.0.1                         :  2.0.1 (OK)
rtree >=0.9.7                        :  0.9.7 (OK)
setuptools >=49.6.0                  :  61.2.0 (OK)
sphinx >=0.6.6                       :  4.5.0 (OK)
spyder_kernels >=2.3.0;<2.4.0        :  2.3.0 (OK)
textdistance >=4.2.0                 :  4.2.2 (OK)
three_merge >=0.1.1                  :  0.1.1 (OK)
watchdog                             :  2.1.7 (OK)
zmq >=17                             :  22.3.0 (OK)

# Optional:
cython >=0.21                        :  0.29.28 (OK)
matplotlib >=3.0.0                   :  3.5.1 (OK)
numpy >=1.7                          :  1.22.3 (OK)
pandas >=1.1.1                       :  1.4.1 (OK)
scipy >=0.17.0                       :  1.8.0 (OK)
sympy >=0.7.3                        :  1.10.1 (OK)

# Spyder plugins:
spyder_terminal.terminalplugin 1.2.2 :  1.2.2 (OK)
```

</details>
@rhkarls interesting, this is definitely the same behaviour I was getting with an error right after typing the opening bracket. I don't get the same error with your code example though, since updating jedi and parso. I just tried a fresh install of spyder 5.3.0 into a venv and can't replicate the error there either - so perhaps it's something completely external? This is my package list at the moment where everything seems to be working correctly:

<details>

Package                       Version
----------------------------- -----------
alabaster                     0.7.12
arrow                         1.2.2
astroid                       2.11.3
atomicwrites                  1.4.0
attrs                         21.4.0
autopep8                      1.6.0
Babel                         2.10.1
backcall                      0.2.0
bcrypt                        3.2.0
beautifulsoup4                4.11.1
binaryornot                   0.4.4
black                         22.3.0
bleach                        5.0.0
certifi                       2021.10.8
cffi                          1.15.0
chardet                       4.0.0
charset-normalizer            2.0.12
click                         8.1.3
cloudpickle                   2.0.0
colorama                      0.4.4
cookiecutter                  1.7.3
cryptography                  37.0.1
debugpy                       1.6.0
decorator                     5.1.1
defusedxml                    0.7.1
diff-match-patch              20200713
dill                          0.3.4
docutils                      0.17.1
entrypoints                   0.4
fastjsonschema                2.15.3
flake8                        4.0.1
idna                          3.3
imagesize                     1.3.0
importlib-metadata            4.11.3
inflection                    0.5.1
intervaltree                  3.1.0
ipykernel                     6.13.0
ipython                       7.33.0
ipython-genutils              0.2.0
isort                         5.10.1
jedi                          0.18.1
jellyfish                     0.9.0
Jinja2                        3.1.2
jinja2-time                   0.2.0
joblib                        1.1.0
jsonschema                    4.4.0
jupyter-client                7.3.0
jupyter-core                  4.10.0
jupyterlab-pygments           0.2.2
keyring                       23.5.0
lazy-object-proxy             1.7.1
MarkupSafe                    2.1.1
matplotlib-inline             0.1.3
mccabe                        0.6.1
mistune                       0.8.4
mypy-extensions               0.4.3
nbclient                      0.6.0
nbconvert                     6.5.0
nbformat                      5.3.0
nest-asyncio                  1.5.5
numpy                         1.22.3
numpydoc                      1.2.1
packaging                     21.3
pandocfilters                 1.5.0
paramiko                      2.10.4
parso                         0.8.3
pathspec                      0.9.0
pexpect                       4.8.0
pickleshare                   0.7.5
pip                           20.2.3
platformdirs                  2.5.2
pluggy                        1.0.0
poyo                          0.5.0
prompt-toolkit                3.0.29
psutil                        5.9.0
ptyprocess                    0.7.0
pycodestyle                   2.8.0
pycparser                     2.21
pydocstyle                    6.1.1
pyflakes                      2.4.0
Pygments                      2.12.0
pylint                        2.13.7
pyls-spyder                   0.4.0
PyNaCl                        1.5.0
pyparsing                     3.0.8
PyQt5                         5.15.6
PyQt5-Qt5                     5.15.2
PyQt5-sip                     12.10.1
PyQtWebEngine                 5.15.5
PyQtWebEngine-Qt5             5.15.2
pyrsistent                    0.18.1
python-dateutil               2.8.2
python-lsp-black              1.2.1
python-lsp-jsonrpc            1.0.0
python-lsp-server             1.4.1
python-slugify                6.1.2
pytz                          2022.1
pywin32                       303
pywin32-ctypes                0.2.0
pyzmq                         22.3.0
QDarkStyle                    3.0.3
qstylizer                     0.2.1
QtAwesome                     1.1.1
qtconsole                     5.3.0
QtPy                          2.0.1
requests                      2.27.1
rope                          1.0.0
Rtree                         1.0.0
scikit-learn                  1.0.2
scipy                         1.8.0
setuptools                    62.1.0
six                           1.16.0
sklearn                       0.0
snowballstemmer               2.2.0
sortedcontainers              2.4.0
soupsieve                     2.3.2.post1
Sphinx                        4.5.0
sphinxcontrib-applehelp       1.0.2
sphinxcontrib-devhelp         1.0.2
sphinxcontrib-htmlhelp        2.0.0
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.3
sphinxcontrib-serializinghtml 1.1.5
spyder                        5.3.0
spyder-kernels                2.3.0
text-unidecode                1.3
textdistance                  4.2.2
threadpoolctl                 3.1.0
three-merge                   0.1.1
tinycss2                      1.1.1
toml                          0.10.2
tomli                         2.0.1
tornado                       6.1
tqdm                          4.64.0
traitlets                     5.1.1
typing-extensions             4.2.0
ujson                         5.2.0
urllib3                       1.26.9
watchdog                      2.1.7
wcwidth                       0.2.5
webencodings                  0.5.1
wrapt                         1.14.0
yapf                          0.32.0
zipp                          3.8.0

</details>
Thanks @rhkarls for the reproducible case! I'm also seeing this error in the latest Spyder. We'll try to fix it in our next version (5.3.1), to be released in a couple of weeks.

Resolving patch:
diff --git a/spyder/plugins/completion/providers/languageserver/providers/document.py b/spyder/plugins/completion/providers/languageserver/providers/document.py
--- a/spyder/plugins/completion/providers/languageserver/providers/document.py
+++ b/spyder/plugins/completion/providers/languageserver/providers/document.py
@@ -152,7 +152,7 @@ def signature_help_request(self, params):
 
     @handles(CompletionRequestTypes.DOCUMENT_SIGNATURE)
     def process_signature_completion(self, response, req_id):
-        if len(response['signatures']) > 0:
+        if response and len(response['signatures']) > 0:
             response['signatures'] = response['signatures'][
                 response['activeSignature']]
             response['provider'] = LSP_COMPLETION


Test patch: