[Python-Dev] Assignment to __class__

Kevin Jacobs jacobs@penguin.theopalgroup.com
Thu, 9 Jan 2003 07:07:41 -0500 (EST)


Hi all,

I'm testing large chunks of our code base with Python 2.3a1 and have run
into another minor snag.  Five months ago Guido committed a patch to prevent
assigning __class__ for non-heap-types, which was backported to 2.2-maint
two weeks ago in response to SF #658106.  This is a great idea for
preventing nonsensical assignments to None.__class__, or 2.__class__, but it
is too heavy handed in preventing assignments to [1,2,3].__class__,
(1,2,3).__class__ or {1:2,3:4}.__class__.

My specific use-case involves dictionary and list objects.  I define a
classes that inherits from list or dict and add specialized algebraic,
vector and tensor functions over the range and domain of the data in the
list or dictionary.  I _could_ just copy the data into my new objects, but it
is wasteful since these structures can be very large and deeply nested.

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.

Thanks,
-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