This problem arose as a result of a failed test, which failed locally and failed on our CI server.
It turned out that some rather tricky comparison of objects was unintentionally made.
I'm curious right now why the behavior is so different between two installations of the same version of Python (2.7.9).
This test case can probably be simplified further, but this is what I have:
import operator class Thing(dict): def __int__(self, number): return self['number'] def __gt__(self, other): return self['number'] > other thing = Thing({'number': 2}) for o in [ operator.lt, operator.le, operator.eq, operator.ne, operator.ge, operator.gt]: print o print o(0.01, thing) print o(thing, 0.01)
And the result of its local launch is:
<built-in function lt> True False <built-in function le> True False <built-in function eq> False False <built-in function ne> True True <built-in function ge> False True <built-in function gt> False True
But on the CSR Travis server, this is:
<built-in function lt> True True <built-in function le> False True <built-in function eq> False False <built-in function ne> True True <built-in function ge> True False <built-in function gt> True True
What is the comparison behavior for Python, and why does it exhibit this behavior on two installations of the same version?
My initial thought was some kind of id comparison, but looking at the id value, they do not correlate at all with the comparison results.
Update:
This different behavior only happens when the class inherits from dict . When it inherits from object , comparisons behave the same on both installations and produce the same results as the local result above.
Update 2:
I just found that I can simplify the test case even with the __int__ and __gt__ , but if I remove any of these methods, the strange behavior will disappear.