Question about accessing class-attributes.

Steven Taschuk staschuk at telusplanet.net
Tue Apr 29 18:18:42 CEST 2003


Quoth Michael Hudson:
> mis6 at pitt.edu (Michele Simionato) writes:
  [...]
> > 2) why you say this makes classes unhashable ?
> 
> Well, I thought it would.  I was wrong:
  [...]
> Then you get this kind of weirdness:
> 
> />> class C(type):
> |..     def __eq__(self, other):
> |..         return 1
> \__ 

Can't the instances of this metaclass be made sensible for use in
dicts simply with
    def __hash__(self):
        return hash(C)
for example?  (To ensure that if x == y then hash(x) == hash(y),
as desired.)  Or does this do weird things in a metaclass context?

(Ignoring issues arising from the brokenness of the __eq__:
    class foo(object):
        __metaclass__ = C
    foo() == 3               # true!
    hash(foo()) == hash(3)   # probably false
and like cases.)

-- 
Steven Taschuk                          staschuk at telusplanet.net
"Its force is immeasurable.  Even Computer cannot determine it."
                           -- _Space: 1999_ episode "Black Sun"





More information about the Python-list mailing list