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

Properties accessed twice for classes defined interactively #102

Closed
ipython opened this issue May 10, 2010 · 2 comments
Closed

Properties accessed twice for classes defined interactively #102

ipython opened this issue May 10, 2010 · 2 comments
Assignees
Labels
Milestone

Comments

@ipython
Copy link
Collaborator

ipython commented May 10, 2010

Original Launchpad bug 297501: https://bugs.launchpad.net/ipython/+bug/297501
Reported by: fdo.perez (Fernando Perez).

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.

@ipython
Copy link
Collaborator Author

ipython commented May 10, 2010

[ LP comment 1 by: Fernando Perez, on 2008-11-13 06:47:47.661256+00:00 ]

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.

@ghost ghost assigned fperez Apr 10, 2011
@fperez
Copy link
Member

fperez commented Nov 28, 2011

Honestly, I don't think this is fixable while having autocall active. Autocall needs to inspect the objects fairly aggressively and I don't think we can make it work without triggering getattrs. The answer is simply: if your objects have so many side effects that you can't call getattr on them more than once, disable autocall altogether.

Closing here.

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

No branches or pull requests

1 participant