Mutable objects?

Alex Martelli aleax at aleax.it
Thu Jan 17 01:56:47 EST 2002


Magnus Lie Hetland wrote:

> Just wondering... Would it be possible for object() to return a
> mutable instance, sort of instances of
> 
>   class Object: pass
> 
> or something?
> 
> (I'm sure this violates some sort of internal logic; it just seems
> sort of useful when you just need a generic object...)

If any instance of object has a __dict__ then we lose the memory
savings of having __slots__ (and pay for a __dict__ in every
object... nightmarish, as that __dict__ also is-a object...!).

If a direct instance of object has a __dict__ but an indirect one
may or may not have it we're breaking one of the most fundamental
tenets of inheritance (subclassing): subclassing doesn't remove stuff.

If instances of object don't necessarily have a __dict__, what kind
of "mutability" can we use on them?

"Seems sort of useful" is weakish motivation for facing these very
thorny issues, it seems to me.  I don't look at them as "some sort
of internal logic", having to do with mere implementation issues, but
as part and parcel of my mental model of how Python works.


Alex




More information about the Python-list mailing list