Question about accessing class-attributes.

Steven Taschuk staschuk at telusplanet.net
Wed Apr 30 10:13:42 EDT 2003


Quoth Michele Simionato:
  [...]
> Really, I don't see where is the problem. As far as I understand (correct me
> if I am wrong) dictionaries are indexed trough the identifier of their keys
> i.e. hash(A) == id(A). [...]

Unless __hash__ is overridden.

> [...] In this example, since A is not B, it is clear to me 
> that d[B] is not defined and cannot work.

But it seems wrong that we can have A == B and yet d[A] != d[B].
This can occur if A == B does not imply that hash(A) == hash(B).

> This issue has nothing to do with metaclasses:

Absolutely.  It has to do with not overriding __hash__ to be
consistent with the overridden __eq__.

-- 
Steven Taschuk             "The world will end if you get this wrong."
staschuk at telusplanet.net     -- "Typesetting Mathematics -- User's Guide",
                                 Brian Kernighan and Lorrinda Cherry





More information about the Python-list mailing list