[Biopython-dev] Equality in Bio.Restriction.RestrictionType

Peter biopython at maubp.freeserve.co.uk
Thu Jul 8 08:24:28 EDT 2010


Hi Frédéric et al,

One of the things in Python 3 is that overriding equality (done with __eq__
only since __cmp__ has gone) requires you also override __hash__. One
remaining example of this which triggers a deprecation warning within our
test suite when running with the -3 switch in in Bio.Restriction.

I therefore had a look at how __eq__ and __ne__ are defined in the
RestrictionType class - and strangely they do NOT seem to be inverses.

    def __eq__(cls, other):
        """RE == other -> bool

        True if RE and other are the same enzyme."""
        return other is cls

    def __ne__(cls, other):
        """RE != other -> bool.
        isoschizomer strict, same recognition site, same restriction -> False
        all the other-> True"""
        if not isinstance(other, RestrictionType):
            return True
        elif cls.charac == other.charac:
            return False
        else:
            return True

Frédéric - could you clarify the intent here?

Thanks,

Peter



More information about the Biopython-dev mailing list