Repository: spyder-ide/spyder

Issue:
Error while getting completion of function/method definition
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

Get a completion for a definition and then press `Enter`:

![error](https://user-images.githubusercontent.com/16781833/68514644-4e246700-024c-11ea-83a9-2ee85feb3997.gif)


### Traceback
```python-traceback
  File "C:\Users\Daniel\Documents\Spyder\spyder\spyder\plugins\editor\extensions\snippets.py", line 52, in wrapper
    return f(self, *args, **kwargs)
  File "C:\Users\Daniel\Documents\Spyder\spyder\spyder\plugins\editor\extensions\snippets.py", line 236, in _process_text
    self.insert_text(text, line, column)
  File "C:\Users\Daniel\Documents\Spyder\spyder\spyder\plugins\editor\extensions\snippets.py", line 368, in insert_text
    if node.name == 'EPSILON':
AttributeError: 'NoneType' object has no attribute 'name'
WARNING:spyder.widgets.github.backend:Failed to send bug report on Github. response={'code': 401, 'json': {'message': 'Must specify two-factor authentication OTP code.', 'documentation_url': 'https://developer.github.com/v3/auth#working-with-two-factor-authentication'}}
```

## Versions

* Spyder version: 4.0.0.dev0 89653aeac
* Python version: 3.7.3
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```
cloudpickle >=0.5.0          :  1.2.1 (OK)
pygments >=2.0               :  2.4.2 (OK)
qtconsole >=4.5.5            :  4.5.5 (OK)
nbconvert >=4.0              :  5.5.0 (OK)
sphinx >=0.6.6               :  2.1.2 (OK)
pylint >=0.25                :  2.3.1 (OK)
psutil >=0.3                 :  5.6.3 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtpy >=1.5.0                 :  1.8.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.0.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.7.0;<2.0.0:  1.7.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.4 (OK)
cython >=0.21                :  None (NOK)
IPython >=4.0                :  7.7.0 (OK)
matplotlib >=2.0.0           :  3.1.0 (OK)
pandas >=0.13.1              :  0.24.2 (OK)
numpy >=1.7                  :  1.16.4 (OK)
scipy >=0.17.0               :  None (NOK)
pyls >=0.29.3;<0.30.0        :  0.29.3 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
```



Discussion:
@steff456, please take a look at this one.

Resolving patch:
diff --git a/spyder/plugins/editor/extensions/snippets.py b/spyder/plugins/editor/extensions/snippets.py
--- a/spyder/plugins/editor/extensions/snippets.py
+++ b/spyder/plugins/editor/extensions/snippets.py
@@ -361,6 +361,9 @@ def insert_text(self, text, line, column):
             self._remove_selection(start, end)
             line, column = start
         node, snippet, text_node = self._find_node_by_position(line, column)
+        if node is None:
+            self.reset()
+            return
         tokens = tokenize(text)
         token_nodes = [nodes.LeafNode(t.token, t.value) for t in tokens]
         for token in token_nodes:


Test patch: