[Python-Dev] Assignment to class (original) (raw)
Kevin Jacobs jacobs@penguin.theopalgroup.com
Thu, 9 Jan 2003 11:33:57 -0500 (EST)
- Previous message: [Python-Dev] Assignment to __class__
- Next message: [Python-Dev] Assignment to __class__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 9 Jan 2003, Guido van Rossum wrote:
> I suspect that it is possible to come up with better criteria for allowing > safe assignment to class that will still allow the useful technique I > describe above.
You can only set class when the old and new class instance have the same instance layout at the C level. Changing this is impossible given the way objects are implemented in C. This means you can never change a list into a dict or vice versa, because the C structs are different. Or do I misunderstand you? Can you give an example of something you think should be allowed but currently isn't?
Sorry, I was not as clear as I should have been. Here is what used to work, and I hope can be made to work again:
class AlgebraicDict(dict): def doReallyComplexThings(self, foo): ... def add(self, other): ... def mul(self, other): ...
unsuspecting_dict = {1:[1,2],2:3}
unsuspecting_dict.class = AlgebraicDict
TypeError: class assignment: only for heap types
Analogously, we want to transform native lists into AlgebraicLists, which of course has list as a base class.
Hope this clears things up, -Kevin
-- Kevin Jacobs The OPAL Group - Enterprise Systems Architect Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com Fax: (216) 986-0714 WWW: http://www.theopalgroup.com
- Previous message: [Python-Dev] Assignment to __class__
- Next message: [Python-Dev] Assignment to __class__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]