Site __cmp__ is broken
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenQuake (deprecated) |
Fix Released
|
High
|
Unassigned |
Bug Description
The Site class in the openquake.shapes module defines a __cmp__ method. It's broken. It doesn't appear to be used anywhere in the code or in tests so we never noticed.
To reproduce:
>>> from openquake.shapes import Site
>>> a = Site(0.0, 0.0)
>>> b = Site(1.0, 1.0)
>>> sorted([a,b])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "openquake/
return self.hash() == other.hash()
AttributeError: 'Site' object has no attribute 'hash'
It's calling a hash() method which no longer exists. To fix, we can simply use __hash__() instead.
Also, per the python documentation [1], the __cmp__ method is simply doing the wrong thing. It should return a negative int if self < other, 0 if self == other, and a positive integer if self > other.
[1] - http://
description: | updated |
Changed in openquake: | |
status: | New → Confirmed |
importance: | Undecided → High |
milestone: | none → 0.4.6 |
Changed in openquake: | |
assignee: | Lars Butler (lars-butler) → nobody |
tags: | added: defect techdebt |
Changed in openquake: | |
milestone: | 0.5.0 → 0.6.1 |
Lars,
Can you take a look at this and see if it can be fixed/closed
Thank you