Hi Nils,

On 2013-02-17, Nils Bruin <nbr...@sfu.ca> wrote:
> Wouldn't it be possible to accomplish this by assigning hash_by_id to
> tp_hash in, for instance, unique_representation_c.__cinit__?

> Given the
> order in which python executes __alloc__ on extension types, I think
> that would still offer subclasses to set tp_hash to another value if
> they want.

Question: Do we *want* that subclasses can override it? After all, if
they are sub-class of UniqueRepresentation, then they are supposed to
show the unique representation behaviour---which includes that
comparison is by identity.

That's why I suggest to separate the two features of
UniqueRepresentation: Cache on the one hand, comparison by identity on
the other hand. If one wants another hash or another comparison, then
one should inherit from the to-be-created CachedRepresentation, and not
from UniqueRepresentation.

> In fact, if you simply *don't* define hash on unique_representation_c,
> wouldn't you get this hash anyway? (equality on "object" is by
> identity).

I think yes. But what happens if you want "a < b" work in a specific
way? You would probably override __cmp__ (at least this is what many
classes do), and if one overrides __cmp__ without providing __hash__,
then you can't use it in a dictionary.

Cheers,
Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to