From 6c661c43279e243950a05f4fcfaf04ad0694522f Mon Sep 17 00:00:00 2001 From: Johnny Robeson Date: Thu, 2 Jun 2016 17:15:47 -0400 Subject: [PATCH] Replace __cmp__ with rich comparisons for Distance --- beets/autotag/hooks.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index 3de803899..d0e3d9c75 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -17,6 +17,7 @@ from __future__ import division, absolute_import, print_function from collections import namedtuple +from functools import total_ordering import re from beets import logging @@ -288,6 +289,7 @@ class LazyClassProperty(object): return self.value +@total_ordering class Distance(object): """Keeps track of multiple distance penalties. Provides a single weighted distance for all penalties as well as a weighted distance @@ -354,10 +356,13 @@ class Distance(object): key=lambda key_and_dist: (-key_and_dist[1], key_and_dist[0]) ) + def __eq__(self, other): + return self.distance == other + # Behave like a float. - def __cmp__(self, other): - return cmp(self.distance, other) + def __lt__(self, other): + return self.distance < other def __float__(self): return self.distance