[Python-Dev] Assignment to __class__ of module? (Autoloading? (Making Queue.Queue easier to use))

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Oct 14 08:50:29 CEST 2005

Phillip J. Eby wrote:

> I meant that just changing its class is a mutation, and since immutables 
> can be shared or cached, that could lead to problems.  So I do think 
> it's a reasonable implementation limit to disallow changing the 
> __class__ of an immutable.

That's a fair point.

Although I was actually thinking recently of a use
case for changing the class of a tuple, inside a
Pyrex module for database access. The idea was that
the user would be able to supply a custom subclass
of tuple for returning the records. To avoid extra
copying of the data, I was going to create a normal
uninitialised tuple, stuff the data into it, and then
change its class to the user-supplied one.

But seeing as all this would be happening in Pyrex
where the normal restrictions don't apply anyway, I
suppose it wouldn't matter if user code wasn't allowed
to do this.


More information about the Python-Dev mailing list