FRED-2 / Fred2

Python-based framework for computational immunomics
http://fred-2.github.io/
40 stars 29 forks source link

unexpected hash on Allele #210

Closed kmhernan closed 6 years ago

kmhernan commented 6 years ago

Perhaps you intend for the current implementation to behave as it does, but it seems unexpected to me. The __cmp__() works as expected, but the __hash__() does not.

# These are the same alleles
>>> var_a = Allele('A*24:02')
>>> var_b = Allele('A*24:02')

# cmp works
>>> var_a == var_b
True

# Different hash!
>>> var_a.__hash__()
8760768445397
>>> var_b.__hash__()
8760768445389

# Look in dictionary is unexpected
>>> dic = {}
>>> dic[var_a] = None
>>> var_a in dic
True
>>> var_b in dic
False
>>> var_b in dic.keys()
True

That was pretty maddening. thoughts?

Edit: A colleague pointed out this difference that is relevant

>>> str(var_a) == repr(var_a)
False
>>> str(var_a)
'A*24:02'
>>> repr(var_a)
'HLA-A*24:02

# But then this adds another fun wrinkle
>>> repr(var_a) == repr(var_b)
True

That additional HLA bit, is this expected

kmhernan commented 6 years ago

Ok, so even though i had version 2.0.1 before i see in your tags that master is different and so I installed again (still says same version btw!) and it is fixed there. So closing