currently in a `dataclasses.dataclass` based class, you can either have it 
hashable and completely immutable (using frozen=True and eq=True), or you can 
have it hashable but completely mutable (by using unsafe_hash=True)

unsafe_hash provides the convenience of being able to mutate some fields, while 
computing your hash by other, non-mutable fields. But there is nothing 
enforcing the fact that the fields marked with `hash=True` should stay 
immutable, otherwise it completely breaks hashability.

The suggestion is, for the dataclass to throw an error if you try to mutate a 
field that contributes to the hash of that dataclass. Or, to have a flag that 
allows you to do so.

Suggestions for the flag name could be

    @dataclass(freeze_hashable_fields=True)
    class A:
        ...

or


    @dataclass(frozen_hash=True)
    class A:
        ...
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BQ75RNKQKV6KCTZ2UWDU2RNDHDIQNCZG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to