mirror of
https://github.com/openvswitch/ovs
synced 2025-10-25 15:07:05 +00:00
python: Fix object comparisons in Python 3.
Python 3 no longer supports __cmp__. Instead, we have to implement the "rich comparison" operators. We implement __eq__ and __lt__ and use functools.total_ordering to implement the rest. In one case, no __cmp__ method was provided and instead relied on the default behavior provided in Python 2. We have to implement the comparisons explicitly for Python 3. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import functools
|
||||
import uuid
|
||||
|
||||
import six
|
||||
@@ -504,6 +505,7 @@ def _row_to_uuid(value):
|
||||
return value
|
||||
|
||||
|
||||
@functools.total_ordering
|
||||
class Row(object):
|
||||
"""A row within an IDL.
|
||||
|
||||
@@ -572,6 +574,19 @@ class Row(object):
|
||||
# in the dictionary are all None.
|
||||
self.__dict__["_prereqs"] = {}
|
||||
|
||||
def __lt__(self, other):
|
||||
if not isinstance(other, Row):
|
||||
return NotImplemented
|
||||
return bool(self.__dict__['uuid'] < other.__dict__['uuid'])
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, Row):
|
||||
return NotImplemented
|
||||
return bool(self.__dict__['uuid'] == other.__dict__['uuid'])
|
||||
|
||||
def __hash__(self):
|
||||
return int(self.__dict__['uuid'])
|
||||
|
||||
def __getattr__(self, column_name):
|
||||
assert self._changes is not None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user