[Python-bugs-list] [ python-Bugs-712975 ] Cannot change the class of a list

SourceForge.net noreply@sourceforge.net
Mon, 07 Apr 2003 11:29:07 -0700


Bugs item #712975, was opened at 2003-03-31 17:00
Message generated for change (Comment added) made by gvanrossum
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=712975&group_id=5470

Category: Type/class unification
Group: Python 2.3
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Jiba (jiba)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Cannot change the class of a list

Initial Comment:
The class of list (or dict) can no longer be changed in
Python 2.3a2 ; this was possible with Python 2.2.2 (as
long as the new class extend list and has no slot).
When doing so ([].__class__ = ...), i get this error :

TypeError: __class__ assignment: only for heap types


Not being able to change the class of non-mutable
object (e.g. int, float or tuple) is AMHO not a great
loss, but list and dict ARE mutable, and so changing
their class does have a sens !

Typically it can be used to observed a list that you
have not created yourself (see atteched script); i was
relying a lot on such observation features.

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2003-04-07 14:29

Message:
Logged In: YES 
user_id=6380

The reason for the restriction is not (im)mutability, but
the fact that many built-in types have (or can have)
non-standard (de)allocators. A subclass of a built-in type
doesn't necessarily have the same deallocator. If someone
can come up with a patch *AND* a proof that the patch is
correct, I'll consider it, but I'd rather be safe than
sorry. Until then, I'll close this as "won't fix".

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2003-04-01 05:30

Message:
Logged In: YES 
user_id=6656

IMHO, changing the class of an immutable object is, was and
always will be Right Out.

Changing the class of a mutable is dicier.  I personally
don't think it's worth the effort, but assigning to Guido
for pronouncement.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=712975&group_id=5470