This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Cannot change the class of a list
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: gvanrossum, jiba, mwh
Priority: normal Keywords:

Created on 2003-03-31 22:00 by jiba, last changed 2022-04-10 16:07 by admin. This issue is now closed.

Messages (4)
msg15333 - (view) Author: Jiba (jiba) Date: 2003-03-31 22:00
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.
msg15334 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2003-04-01 10:30
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.
msg15335 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-04-07 18:29
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".
msg15336 - (view) Author: Jiba (jiba) Date: 2003-04-16 12:34
Logged In: YES 
user_id=591223

I've submitted a patch for it (#722462), as well as a PyUnit
test case.
History
Date User Action Args
2022-04-10 16:07:58adminsetgithub: 38247
2003-03-31 22:00:45jibacreate