On 29 July 2017 at 04:56, Mike Miller <python-id...@mgmiller.net> wrote:
> Nice.  Ok, so there are different dimensions of mutability.
>
> Still, haven't found any "backdoors" to object(), the one I claimed was
> immutable.

It's possible to write builtin types that are truly immutable, and
there are several examples of that (direct instances of object, tuple
instances, instances of the builtin numeric types), but it isn't
particularly straightforward to make Python defined classes truly
immutable.

While this gets close for stateless instances (akin to instantiating
object() directly):

    >>> class MostlyImmutable:
    ...     __slots__ = ()
    ...     @property
    ...     def __class__(self):
    ...         return type(self)
    ...

It's far more difficult to actually store any meaningful state without
making it open to mutation in some way (since it needs to settable
from __new__, and Python doesn't provide any inherent mechanism from
distinguishing those cases from post-creation modifications).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to