Carl Banks <pavlovevide...@gmail.com> writes:

> On Jan 23, 11:45 pm, Bryan Olson <fakeaddr...@nowhere.org> wrote:
>> Carl Banks wrote:
>> > Classes in Python are mutable types, usually.  Class instances are
>> > (except for the refcount) immutable objects, usually.
>>
>> There's where we disagree. I assert that class instances are usually
>> mutable objects.
>
> Nope, you're dead wrong, nothing more to it.  The bits of a class
> instance never change.  The __dict__ is a mutable object.  The class
> instance itself isn't.  It's not reasonable to call an object whose
> bits can't change a mutable obect.

The "bits" of class instances can very well change.

>>> class X(object): pass
...
>>> x = X()
>>> d = x.__dict__
>>> x.__dict__ = {}
>>> map(id, [d, x.__dict__])
[170329876, 170330012]

The Python cookbook even describes patterns that depend on this
operation working.  Class instance's contents can also change if
__slots__ is in use, when its __class__ is assigned to (admittedly the
latter being a rare operation, but still).

> Anyway, all you're doing is distracting attention from my claim that
> instance objects wouldn't need to be locked.  They wouldn't, no
> matter how mutable you insist these objects whose bits would never
> change are.

Only if you're not implementing Python, but another language that
doesn't support __slots__ and assignment to instance.__dict__.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to