Repository: spyder-ide/spyder

Issue:
File execution fails with AttributeError: _Feature instance has no attribute '__len__'
## Description of your problem

1. Using `from __future__ import print_function` and 
2. importing pdb and setting `pdb.set_trace()`
lets the file-execution terminate with the error statement:
`AttributeError: _Feature instance has no attribute '__len__' `. 

**What steps will reproduce the problem?**

1. Run the following file with F5:

```python
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 28 14:47:12 2017
@author: Speedy Gonzalez
"""
from __future__ import print_function
import pdb
class speedy(object):
    def hello_world(self):
        pdb.set_trace()
        print('Hello world!')
        return
speedyo = speedy()
```

2. In the IPython-console type: speedyo.hello_world()
3. 

**What is the expected output? What do you see instead?**
Expected:
1. file starts with the debugger and the ipdb command line: ipdb>
2.  After typing 'c' the words 'Hello world!' are printed in the IPython-console.

Instead the following output appears:

```python-traceback
In [2]: speedyo.hello_world()
Traceback (most recent call last):
  File "<ipython-input-2-c923dc13a4b5>", line 1, in <module>
    speedyo.hello_world()
  File "C:/Users/Public/SVN_Workspace/ltc_2947_8_9/lab/python/axels.py", line 16, in hello_world
    print('Hello world!')
  File "C:/Users/Public/SVN_Workspace/ltc_2947_8_9/lab/python/axels.py", line 16, in hello_world
    print('Hello world!')
  File "c:\python27_64\lib\bdb.py", line 49, in trace_dispatch
    return self.dispatch_line(frame)
  File "c:\python27_64\lib\bdb.py", line 67, in dispatch_line
    self.user_line(frame)
  File "c:\python27_64\lib\pdb.py", line 158, in user_line
    self.interaction(frame, None)
  File "c:\python27_64\lib\site-packages\spyder\utils\site\sitecustomize.py", line 414, in interaction
    self.notify_spyder(frame)
  File "c:\python27_64\lib\site-packages\spyder\utils\site\sitecustomize.py", line 352, in notify_spyder
    ipython_shell.kernel.publish_pdb_state()
  File "c:\python27_64\lib\site-packages\spyder\utils\ipython\spyder_kernel.py", line 219, in publish_pdb_state
    var_properties = self.get_var_properties(),
  File "c:\python27_64\lib\site-packages\spyder\utils\ipython\spyder_kernel.py", line 132, in get_var_properties
    'len': self._get_len(value),
  File "c:\python27_64\lib\site-packages\spyder\utils\ipython\spyder_kernel.py", line 322, in _get_len
    return len(var)
AttributeError: _Feature instance has no attribute '__len__'
```

**Please provide any additional information below**
When commenting out the line 'from __future__ import print_function'
_and_ restarting the IPython-console the behavior is as expected - no crash.

## Versions and main components

* Spyder Version: 3.2.0
* Python Version: 2.7.13 64 bits
* Qt Version:  4.8.7
* PyQt Version: 4.11.4
* Operating system: Windows


## Dependencies

Please go to the menu entry `Help > Optional Dependencies` (or
`Help > Dependencies`), press the button `Copy to clipboard`
and paste the contents below:
IPython >=4.0;<6.0:  5.4.1 (OK)
cython >=0.21     :  None (NOK)
jedi >=0.9.0      :  0.10.2 (OK)
nbconvert >=4.0   :  5.2.1 (OK)
numpy >=1.7       :  1.12.0 (OK)
pandas >=0.13.1   :  None (NOK)
pycodestyle >=2.3 :  2.3.1 (OK)
pyflakes >=0.5.0  :  1.5.0 (OK)
pygments >=2.0    :  2.2.0 (OK)
pylint >=0.25     :  1.7.2 (OK)
qtconsole >=4.2.0 :  4.3.0 (OK)
rope >=0.9.4      :  0.10.5 (OK)
sphinx >=0.6.6    :  1.6.3 (OK)
sympy >=0.7.3     :  None (NOK)




Discussion:
@AxelMKlein, thanks for reporting. We'll fix this error in our 3.2.1 version.

@dalthviz, the fix for this one is quite simple: please remove the `TypeError` exception of the `_get_len` method present in `SpyderKernel`.

Let's also take the opportunity to remove `AttributeError` from `_get_array_shape` and `_get_array_ndim` to avoid similar errors in the future.

Resolving patch:
diff --git a/spyder/utils/ipython/spyder_kernel.py b/spyder/utils/ipython/spyder_kernel.py
--- a/spyder/utils/ipython/spyder_kernel.py
+++ b/spyder/utils/ipython/spyder_kernel.py
@@ -320,7 +320,7 @@ def _get_len(self, var):
         """Return sequence length"""
         try:
             return len(var)
-        except TypeError:
+        except:
             return None
 
     def _is_array(self, var):
@@ -362,7 +362,7 @@ def _get_array_shape(self, var):
                 return var.shape
             else:
                 return None
-        except AttributeError:
+        except:
             return None
 
     def _get_array_ndim(self, var):
@@ -372,7 +372,7 @@ def _get_array_ndim(self, var):
                 return var.ndim
             else:
                 return None
-        except AttributeError:
+        except:
             return None
 
     # --- For Pdb


Test patch: