[Biopython-dev] [Bug 2437] comparing alphabet references causes assert to fail when it should pass

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Mon Mar 3 21:53:59 UTC 2008


http://bugzilla.open-bio.org/show_bug.cgi?id=2437





------- Comment #2 from biopython-bugzilla at maubp.freeserve.co.uk  2008-03-03 16:53 EST -------
Defining __eq__ and __ne__ methods for the Alphabet class would probably work,
but we would also have to do this for the AlphabetEncoder "decorator" class. 
I'm a little wary of this...

    def __ne__(self, other) :
        """Check if this alphabet object <> another alphabet"""
        return not self == other

    def __eq__(self, other) :
        """Check if this alphabet object == another alphabet"""
        #TODO - what exactly do we want to check here?
        if id(self) == id(other) :
            return True
        if not isinstance(other, Alphabet) \
        and not isinstance(other, AlphabetEncoder):
            raise ValueError("Comparing an alphabet to a non-alphabet")
        if self.__class__ <> other.__class__ :
            return False
        if self.size <> other.size :
            return False
        if self.letters <> other.letters :
            return False
        if dir(self) <> dir(other) :
            return False
        for attr in ["gap_char", "stop_symbol"] :
            if hasattr(self, attr) <> hasattr(other, attr) :
                return False
            if hasattr(self, attr) and hasattr(other, attr) \
            and self.__getattr__(attr) <> other.__getattr_(attr) :
                return False
        #Close enough?
        return True

Relaxing the assertion in Bio.Translate would be much safer in terms of any
potential side effects.


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the Biopython-dev mailing list