[issue24991] Define instance mutability explicitly on type objects?

Raymond Hettinger report at bugs.python.org
Sun Dec 10 14:08:38 EST 2017


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

I think this is a hazardous path that should be avoided.  Mutability is an elusive concept that is hard to pin down.

Files are immutable when opened in a read-only mode and mutable if opened in a write mode.  Tuples are immutable but may contain mutable elements.  Tuples are immutable to Python programmers but fully mutable to C programmers.  Some objects have some fields than can be mutated and some that can't.  Regular Python classes are always mutable in the sense that there is usually some path to changing almost everything even if __setattr__ has been overridden.  It is more a matter of convention (public API) than a technical point.

I prefer that Python be left as a "consenting adults" language rather than go down this precarious path.  For comparison, think about the issue of constants in Python.  A constant is just a variable that by convention you don't change.  It isn't declared or enforced, yet for the most part this is just fine.

----------
assignee:  -> rhettinger
nosy: +rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue24991>
_______________________________________


More information about the Python-bugs-list mailing list