Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File execution fails with AttributeError: _Feature instance has no attribute '__len__' #4862

Closed
AxelMKlein opened this issue Jul 31, 2017 · 1 comment

Comments

@AxelMKlein
Copy link

AxelMKlein commented Jul 31, 2017

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:
# -*- 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()
  1. In the IPython-console type: speedyo.hello_world()

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:

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)

@AxelMKlein AxelMKlein changed the title Spyder 3.2.0, Python 2.7.13: pdb: Python file execution fails with 'AttributeError: _Feature instance has no attribute '__len__' ' with 'from __future__ import print_function' Spyder 3.2.0, Python 2.7.13: pdb: Python file execution fails with 'AttributeError: _Feature instance has no attribute '__len__' ' when using 'from __future__ import print_function' Jul 31, 2017
@ccordoba12 ccordoba12 added this to the v3.2.1 milestone Jul 31, 2017
@ccordoba12 ccordoba12 changed the title Spyder 3.2.0, Python 2.7.13: pdb: Python file execution fails with 'AttributeError: _Feature instance has no attribute '__len__' ' when using 'from __future__ import print_function' File execution fails with AttributeError: _Feature instance has no attribute __len__ Jul 31, 2017
@ccordoba12 ccordoba12 changed the title File execution fails with AttributeError: _Feature instance has no attribute __len__ File execution fails with AttributeError: _Feature instance has no attribute '__len__' Jul 31, 2017
@ccordoba12
Copy link
Member

ccordoba12 commented Jul 31, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants