Daniel Lindeman <linde...@gmail.com> added the comment:
A possible use case would be a field that represents an auto-incrementing
database ID. Since the field is auto-incrementing in the database, it would be
desirable to keep this field frozen, and others mutable once an instance of a
data class is created.
This is also a feature of data classes in other languages, for example Kotlin:
https://kotlinlang.org/docs/reference/data-classes.html . The main difference
here being that we don't have val and var, and thus mutability and immutability
are harder to represent.
Hashing could be implemented such that frozen fields are allowed to be part of
the hash, but unfrozen fields would remain only part of the hash when
unsafe_hash is set. I believe equality follows from hashing, so the same rules
should apply.
The conflict between setting the class to frozen, and a field to not frozen
could be solved by raising an exception.
Upon investigation, attrs does not support this behavior. I can try this
feature with attrs, but their implementation may differ enough to make it
infeasible.
--
___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33474>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com