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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4