Repository: spyder-ide/spyder
Pull request: PR: Check if responses are not None in Kite plugin handlers
<!--- 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



### Issue(s) Resolved

<!--- List the issue(s) below, in the form "Fixes #1234"; one per line --->

Fixes #10029
Fixes #9993


### 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: @goanpeca 

<!--- Thanks for your help making Spyder better for everyone! --->


Problem statement:
TypeError in Kite client
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

When I open up Spyder, after a while (a few seconds), the Issue reporter window pops up. It seems that there's something wrong with kite autocompletion

### Traceback
```python-traceback
  File "C:\Users\Amin\Anaconda3\envs\pmeal\lib\site-packages\spyder\plugins\completion\kite\client.py", line 135, in perform_request
TypeError: 'NoneType' object is not subscriptable
```

## Versions

* Spyder version: 4.0.0b4 
* Python version: 3.7.2
* Qt version: 5.9.7
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```
pygments >=2.0    :  2.4.2 (OK)
qdarkstyle >=2.6.4:  2.7 (OK)
sphinx >=0.6.6    :  2.1.2 (OK)
pyls >=0.27.0     :  0.28.0 (OK)
nbconvert >=4.0   :  5.6.0 (OK)
pandas >=0.13.1   :  0.25.0 (OK)
numpy >=1.7       :  1.15.0 (OK)
sympy >=0.7.3     :  1.4 (OK)
cython >=0.21     :  None (NOK)
qtconsole >=4.5.2 :  4.5.2 (OK)
IPython >=4.0     :  7.2.0 (OK)
matplotlib >=2.0.0:  None (NOK)
pylint >=0.25     :  2.3.1 (OK)
```


Ignore ConnectionError on Kite completions request
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

## Problem Description

If Kite is running when Spyder is started, but then exits (e.g. crashes, or manually), Spyder reports `ConnectionError`s whenever making completions requests.

### What steps reproduce the problem?

1. Start Kite
2. Start Spyder
3. Wait until Kite completions are working
4. Quit Kite
5. Type in Spyder

### What is the expected output? What do you see instead?

No Kite completions should show up, and no error should be reported, since I quit Kite. Instead, I see an error:

```python-traceback

raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=46624): Max retries exceeded with url: /clientapi/editor/event (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe1e8a996d0>: Failed to establish a new connection: [Errno 61] Connection refused'))

```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: master
* Python version: 3.7
* Qt version: 5.9.7
* PyQt version: 5.9.2
* Operating System name/version: Darwin 10.12.6

Hints from issue discussion:
@ma-sadeghi, thanks for reporting. Do you have Kite installed in your system?

@andfoy, please take a look at this one.
@ccordoba12 yes, I have Kite installed.
We're not preventing None responses to not be attended. I'll fix this
Thanks @metalogical for the report!

Commit message: Check response is not None

Patch to review:
diff --git a/spyder/plugins/completion/kite/providers/document.py b/spyder/plugins/completion/kite/providers/document.py
index 8bec7243e24..82311c3fa6e 100644
--- a/spyder/plugins/completion/kite/providers/document.py
+++ b/spyder/plugins/completion/kite/providers/document.py
@@ -116,10 +116,14 @@ def request_hover(self, params):
     @handles(LSPRequestTypes.DOCUMENT_HOVER)
     def process_hover(self, response):
         # logger.debug(response)
-        report = response['report']
-        text = report['description_text']
-        if len(text) == 0:
+        if response:
+            report = response['report']
+            text = report['description_text']
+            if len(text) == 0:
+                text = None
+        else:
             text = None
+
         return {'params': text}
 
     @send_request(method=LSPRequestTypes.DOCUMENT_SIGNATURE)


Code review comments:
diff_hunk: @@ -116,10 +116,14 @@ def request_hover(self, params):
     @handles(LSPRequestTypes.DOCUMENT_HOVER)
     def process_hover(self, response):
         # logger.debug(response)
path: spyder/plugins/completion/kite/providers/document.py
text: @user1:
Please uncomment this line.

diff_hunk: @@ -116,10 +116,14 @@ def request_hover(self, params):
     @handles(LSPRequestTypes.DOCUMENT_HOVER)
     def process_hover(self, response):
         # logger.debug(response)
-        report = response['report']
-        text = report['description_text']
-        if len(text) == 0:
+        if response:
path: spyder/plugins/completion/kite/providers/document.py
text: @user1:
Perhaps we should change this to

    if response is not None:

to be more explicit.