[issue24991] Define instance mutability explicitly on type objects?

Nick Coghlan report at bugs.python.org
Mon Dec 25 18:58:24 EST 2017


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Declaring "I intend for instances of this class to be immutable" isn't a fuzzy concept - it's in the same vein as other type hints, like "I intend for this to be a string". The part that's fuzzy is how well Python actually enforces that declaration, and hence the degree to which you can actually rely on it at runtime.

In most cases, detecting and reporting *violations* of that intent would be in the realm of typecheckers rather than the language interpeter, but there'd be cases where the interpreter itself could make useful inferences from such a declaration (for example, by prohibiting conventional mutation operations, the way "frozen=True" does for data classes).

----------

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


More information about the Python-bugs-list mailing list