Repository: spyder-ide/spyder
Pull request: PR: Add validation for empty signature while getting calltip in the IPython Console
<!--- 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 --->




### Issue(s) Resolved

<!--- List the issue(s) below, in the form "Fixes #1234"; one per line --->

Fixes #9570 


### 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:
Error for calltip with empty signature
## Description

### What steps will reproduce the problem?

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

import os

os.getcwd( -> triggers calltip but an error raises


### Traceback
```python-traceback
  File "C:\Users\Daniel\Anaconda3\envs\spyder4\lib\site-packages\qtconsole\base_frontend_mixin.py", line 138, in _dispatch
    handler(msg)
  File "C:\Users\Daniel\Desktop\Spyder\spyder\spyder\plugins\ipythonconsole\widgets\help.py", line 141, in _handle_inspect_reply
    documentation = self.get_documentation(content)
  File "C:\Users\Daniel\Desktop\Spyder\spyder\spyder\plugins\ipythonconsole\widgets\help.py", line 46, in get_documentation
    documentation = text.split(signature)
ValueError: empty separator
```

## Versions

* Spyder version: 4.0.0.dev0 eb70e6b6d
* Python version: 3.7.3
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 8.1

### Dependencies

```
pygments >=2.0     :  2.4.0 (OK)
qdarkstyle >=2.6.4 :  2.6.8 (OK)
sphinx >=0.6.6     :  2.0.1 (OK)
pyls >=0.19.0;<0.25:  0.24.0 (OK)
nbconvert >=4.0    :  5.5.0 (OK)
pandas >=0.13.1    :  0.24.2 (OK)
numpy >=1.7        :  1.16.3 (OK)
sympy >=0.7.3      :  1.4 (OK)
cython >=0.21      :  0.29.7 (OK)
qtconsole >=4.2.0  :  4.5.1 (OK)
IPython >=4.0      :  7.5.0 (OK)
matplotlib >=2.0.0 :  3.0.3 (OK)
pylint >=0.25      :  2.3.1 (OK)
```

Hints from issue discussion:
Thanks for reporting @dalthviz will fix it now
Hi @dalthviz sorry, I thought this was related to the code editor. I think you have more xp with the ipython console :-p. Could you fix it?

---
Also if I try doing on the ipython console

```python
import subprocess
subprocess.Popen(
```

I am getting

```python-traceback
  File "/Users/gpena-castellanos/anaconda2/envs/spyder/lib/python2.7/site-packages/qtconsole/base_frontend_mixin.py", line 138, in _dispatch
    handler(msg)
  File "/Users/gpena-castellanos/Dropbox (Personal)/develop/quansight/spyder/spyder/plugins/ipythonconsole/widgets/help.py", line 146, in _handle_inspect_reply
    language=self.language_name,
AttributeError: 'ShellWidget' object has no attribute 'language_name'
```

@goanpeca, you need to update qtconsole to fix that error.
Right I forgot
@goanpeca no worries, actually I think the error is part of the changes I made to show documentation in the calltips of the IPython Console, so I will work on it :+1: 
Thanks!

Commit message: IPython Console: Add validation for empty signature while getting doc

Patch to review:
diff --git a/spyder/plugins/ipythonconsole/widgets/help.py b/spyder/plugins/ipythonconsole/widgets/help.py
index 039b5f97ebb..a85586eba36 100644
--- a/spyder/plugins/ipythonconsole/widgets/help.py
+++ b/spyder/plugins/ipythonconsole/widgets/help.py
@@ -43,9 +43,10 @@ def get_documentation(self, content):
         text = data.get('text/plain', '')
         signature = self.get_signature(content).split('(')[-1]
         if text:
-            documentation = text.split(signature)
-            if len(documentation) > 1:
-                return documentation[-1]
+            if signature:
+                documentation = text.split(signature)
+                if len(documentation) > 1:
+                    return documentation[-1]
 
     def get_signature(self, content):
         """Get signature from inspect reply content"""
@@ -62,6 +63,7 @@ def get_signature(self, content):
                 name = self.clean_invalid_var_chars(name)
             except:
                 pass
+
             text = text.split('Docstring:')[-1]
             argspec = getargspecfromtext(text)
             if argspec:


Code review comments:
diff_hunk: @@ -43,9 +43,10 @@ def get_documentation(self, content):
         text = data.get('text/plain', '')
         signature = self.get_signature(content).split('(')[-1]
         if text:
-            documentation = text.split(signature)
-            if len(documentation) > 1:
-                return documentation[-1]
+            if signature:
+                documentation = text.split(signature)
+                if len(documentation) > 1:
+                    return documentation[-1]
path: spyder/plugins/ipythonconsole/widgets/help.py
text: @user1:
I think this would avoid showing documentation for objects without signature, right? I mean, if there's no signature we should still show the documentation (if `text` has some content).