Site __cmp__ is broken

Bug #885614 reported by Lars Butler
6
This bug affects 1 person
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/shapes.py", line 370, in __cmp__
    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://docs.python.org/reference/datamodel.html#object.__cmp__

description: updated
John Tarter (toh2)
Changed in openquake:
status: New → Confirmed
importance: Undecided → High
milestone: none → 0.4.6
Revision history for this message
John Tarter (toh2) wrote :

Lars,
Can you take a look at this and see if it can be fixed/closed
Thank you

Changed in openquake:
milestone: 0.4.6 → 0.5.0
assignee: nobody → Lars Butler (lars-butler)
Revision history for this message
Lars Butler (lars-butler) wrote :

John: This still needs to be fixed.

Changed in openquake:
assignee: Lars Butler (lars-butler) → nobody
tags: added: defect techdebt
Revision history for this message
Muharem Hrnjadovic (al-maisan) wrote :

This method seems unused, removing Site.__cmp__() and running tests and q/a tests causes no apparent errors.

John Tarter (toh2)
Changed in openquake:
milestone: 0.5.0 → 0.6.1
Revision history for this message
Lars Butler (lars-butler) wrote :

This entire module doesn't exist anymore. I'll call it "fixed". =)

Changed in openquake:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related blueprints

Remote bug watches

Bug watches keep track of this bug in other bug trackers.