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
irregular behavior within class using __setitem__ #42461
Comments
i found two bugs vaguely similar to this posted but i basically the class is a modified list, being used as a what happens is, when hotswapping the __setitem__ this is very odd and as far as i can tell the behavior is class Queue(list):
def __setitem__(self, a, v):
print "old setitem"
def mysetitem(self, i, v):
print "new setitem"
def use_mysetitem(self):
self.__setitem__ = self.mysetitem
x = Queue() x[1] = 2 x.__setitem__(2, 3)
x.use_mysetitem()
x[3] = 4
x.__setitem__(4, 5) |
Logged In: YES This problem doesn't exist in Python 2.4: Py> class Queue(list): |
Logged In: YES err, yeh it does 8) |
Logged In: YES Ah, sorry. I was looking at the wrong part of the printout. |
Logged In: YES And now that I've read the bug report properly, I'm closing To affect the operators you need to alter the slot on the To make the method work, it needs to be a class method: def use_mysetitem(cls):
cls.__setitem__ = cls.mysetitem
use_mysetitem = classmethod(use_mysetitem) Of course, it will then affect *all* instances of the class You can get per-instance swapping by writing the slot method |
Logged In: YES omg! you're lucky people on freenode spared you a half hour and after almost 4 hours of completely going around the world [05:38] <squ1g3e> what if i want to change the class within haha thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: