IPython - Enhanced Interactive Python

Properties accessed twice for classes defined interactively

Reported by Fernando Perez on 2008-11-13
2
Affects Status Importance Assigned to Milestone
IPython
Confirmed
Undecided
Unassigned

Bug Description

Reported on the ipython-user list:

I am experiencing some unusual behavior *only* when I am directly
working in the ipython shell. The problem involves the get method for
a property.

class MyClass():
   def __init__(self):
       self._x = 3
   def getx(self):
       print "getting x"
       return self._x
   def setx(x):
       print "setting x"
       self._x = x
   x = property(getx, setx)

a = MyClass()
a.x # prints "getting x" twice
print a.x # prints "getting x" once

If you stick all this in a file and do 'run test.py', the problem does
not occur. Also, notice that it does not occur in the "print a.x"
statement.

Fernando Perez (fdo.perez) wrote :

This is indeed happening, and it's another manifestation of the problems with __getattr__ that have also been reported here:

https://bugs.launchpad.net/ipython/+bug/244677

Similarly, the problem can be avoided by turning %autocall completely off. We still need to investigate whether we can fine-tune %autocall to still work while producing less spurious __getattr__ calls.

Changed in ipython:
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers