__eq__() inconvenience when subclassing set

Jess Austin jess.austin at gmail.com
Thu Oct 29 16:19:19 EDT 2009


On Oct 28, 10:07 pm, Mick Krippendorf <mad.m... at gmx.de> wrote:
> You could just overwrite set and frozenset:
>
> class eqmixin(object):
>     def __eq__(self, other):
>         print "called %s.__eq__()" % self.__class__
>         if isinstance(other, (set, frozenset)):
>             return True
>         return super(eqmixin, self).__eq__(other)
>
> class frozenset(eqmixin, frozenset):
>     pass

That's nice, but it means that everyone who imports my class will have
to import the monkeypatch of frozenset, as well.  I'm not sure I want
that.  More ruby than python, ne?

thanks,
Jess



More information about the Python-list mailing list