assignment to __class__ (was Re: Copy constructors)
Terry Reedy
tjreedy at home.com
Mon Aug 13 23:35:31 EDT 2001
"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:9l9d4k02opd at enews4.newsguy.com...
> "Guido van Rossum" <guido at python.org> wrote in message
> news:cpzo94dqvy.fsf at cj20424-a.reston1.va.home.com...
> ...
> > http://www.python.org/2.2/descrintro.html
>
> I thought I had understood it, but still don't see where it mentions
> "x.__class__ = whatever" now being forbidden or restricted?
I rechecked. It does not. Did find
"For instance of built-in types, x.__class__ is now the same as
type(x): "
which does hint that it might be problematical for subtypes.
Is the proposed restriction for subtype insstances only or also for
subclass instances?
> > It would be relatively easy to allow __class__ assignment only if
(a)
> > the new class is a subclass of the old class, and (b) the size of
the
> > new instance is the same as the old instance. Would this be
sufficient?
Given that there are sensible reason to mutate instances (to reflect
real or virtual mutations - see Another two examples of using changing
classes by Itamar Shtull-Trauring and my reply) this would seem
desirable.
Terry J. Reedy
More information about the Python-list
mailing list