buitlins instance have modifiable __class__?

question on bultin types (under 2.2):
d={} class ndict(dict):
... __slots__ = () ... def __getitem__(self,k): ... print "__getitem__" ... return dict.__getitem__(self,k) ...
d.items()
[]
d['a']=3 d.__class__=ndict
is intended to work?
it seems it does, but is that the intention?
d['a']
__getitem__ 3
[
exec "print a" in d
3
Ok, that is the non cooperative behavior I already know about. ]
Thanks.

typos apart, there was also another question, sorry I was typing and reflecting on the consequences of all of this on Jython ...
[me]
exec "print a" in d
3
Ok, that is the non cooperative behavior I already know about. ]
I recall this was already discussed here, what is the idea, to leave it as it is or make this work?
Thanks.

question on bultin types (under 2.2):
d={} class ndict(dict):
... __slots__ = () ... def __getitem__(self,k): ... print "__getitem__" ... return dict.__getitem__(self,k) ...
d.items()
[]
d['a']=3 d.__class__=ndict
is intended to work?
it seems it does, but is that the intention?
It was a mistake. In 2.3, it's disallowed. In 2.2.2, it'll still be allowed, but you shouldn't do this -- all sorts of bizarre stuff can happen because you can do this.
So if you're asking about this for Jython, please don't allow this in Jython!
typos apart, there was also another question, sorry I was typing and reflecting on the consequences of all of this on Jython ...
[me]
exec "print a" in d
3
Ok, that is the non cooperative behavior I already know about. ]
I recall this was already discussed here, what is the idea, to leave it as it is or make this work?
That's not going to change in CPython, because I believe it would slow down lookup for builtins and globals too much if we had to check for a custom __getitem__. But if you can fix it for Jython, go ahead. I don't mind if there are places where Jython is "purer" than CPython.
--Guido van Rossum (home page: http://www.python.org/~guido/)

From: Guido van Rossum guido@python.org
It was a mistake. In 2.3, it's disallowed. In 2.2.2, it'll still be allowed, but you shouldn't do this -- all sorts of bizarre stuff can happen because you can do this.
So if you're asking about this for Jython, please don't allow this in Jython!
honestly I was hoping that it was unintended, implementing this would make already complicated things even more so. So we are happy campers.
Maybe others will be less so, I have seen a module referred on c.l.p using the "feature" escaped from the lab to make builtins observable <wink>.
exec "print a" in d
3
Ok, that is the non cooperative behavior I already know about. ]
I recall this was already discussed here, what is the idea, to leave it as it is or make this work?
That's not going to change in CPython, because I believe it would slow down lookup for builtins and globals too much if we had to check for a custom __getitem__. But if you can fix it for Jython, go ahead. I don't mind if there are places where Jython is "purer" than CPython.
Very likely the other way is what we will get in Jython by doing nothing
regards.

[me]
Maybe others will be less so, I have seen a module referred on c.l.p using
the
"feature" escaped from the lab to make builtins observable <wink>.
the thread on c.l.p is google: watching mutables? group:comp.lang.python
the package is at
http://oomadness.tuxfamily.org/en/editobj/
author: Jean-Baptiste LAMY -- jiba@tuxfamily
I have directly attached the "incriminated" module for the curious.
Should I give them the bad news?
regards.
participants (2)
-
Guido van Rossum
-
Samuele Pedroni