hynek / characteristic

Please use attrs instead!
https://attrs.readthedocs.io/
MIT License
84 stars 19 forks source link

Update docs with mention of how @with_cmp affects .__hash__() #35

Open paulie-g opened 9 years ago

paulie-g commented 9 years ago

I have run into this use case a few times now: I want all of characteristic's goodness for the entire set of attributes, but it only makes sense for .hash() to reference some subset of of them, because the rest are not meaningful in that context. Characteristic already has a facility to make this distinction for compares (with_cmp/exclude_from_cmp) and I'd like to submit a PR that does it for hashes as well in an analogous manner.

Any objections @hynek ? :+1:

paulie-g commented 9 years ago

... and it becomes clear from reading the code that \@with_cmp makes .hash() behave in the exact way needed to satisfy this use case. Perhaps a mention of this in the docs might be useful?

hynek commented 9 years ago

I'm traveling right now but for now is like to mention characteristic's fork hynek/attrs that does hash separately because I ran into frequent problems with mutable members.

(I'll look at your PR once I'm back)

paulie-g commented 9 years ago

Thanks for the pointer, I'll be using attrs from now on. It's got a number of small improvements, but there are so many that it adds up to a big difference in usability and elegance. As far as mutable members interacting with hashes goes, that's expected. There are several ways of dealing with that edge case, but none are general enough imo to make them foolproof, so I'd say leaving the burden with the user is acceptable there.

The pull request is just a doc change, no hurry there.

hynek commented 9 years ago

Heh yeah, attrs is born out of my own frustrations with characteristic; hence that effect. :)