Closed NicholasFiorentini closed 5 months ago
They are not immutable, so hashing doesn't make sense. You can change them at any time invalidating any hash I could generate.
You can manually save the color data as a hashable object, or serialize them as a hashable string, but the color object itself is mutable. This is the same reason dictionaries and lists aren't hashable.
If hashing is an absolute requirement for your specific usage, I think subclassing the object and hashing it yourself is perfectly fine. The caveat is that if you accidentally modify a color it would change its hash and potentially create a collision in your structure, but if you are comfortable with that risk and think the likeliness of such accidents is low, then it's a fine solution.
They are not immutable, so hashing doesn't make sense. You can change them at any time invalidating any hash I could generate.
Ah, I see. At first, I missed that Color
is a mutable object.
Thanks for clarifying.
I wanted to use
Color
in a frozendataclass
but, unfortunately, it is not hashable and it cannot be used directly.Minimal example
Proposed solution
I implemented this very naive solution:
Could this be part of coloraide's
Color
? Or there is a reason whyColor
is not hashable?