[py3k] object no longer has a default __lt__

In python 2:

Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address.

In python 3:

Instances of a class cannot be ordered with respect to other instances of the same class, or other types of object, unless the class defines enough of the methods __lt__(), __le__(), __gt__(), and __ge__().

Related to #296242.

authorRémi Cardona <remi.cardona@free.fr>
changeset36ea0996d803
branchdefault
phasepublic
hiddenno
parent revision#c7494a3a871a [py3k] reduce is now in the functools module
child revision#46faa71adafd [py3k] next(iterator) instead of iterator.next()
files modified by this revision
propagation.py
test/test_constraints.py
test/test_distributors.py
test/test_domains.py
# HG changeset patch
# User Rémi Cardona <remi.cardona@free.fr>
# Date 1405931261 -7200
# Mon Jul 21 10:27:41 2014 +0200
# Node ID 36ea0996d803d315f4e946927e99bce22d675b0f
# Parent c7494a3a871a0594e966aa2a61580a38abef0876
[py3k] object no longer has a default __lt__

In python 2:

Objects of different types except numbers are ordered by their type
names; objects of the same types that don’t support proper comparison
are ordered by their address.

In python 3:

Instances of a class cannot be ordered with respect to other instances
of the same class, or other types of object, unless the class defines
enough of the methods __lt__(), __le__(), __gt__(), and __ge__().

Related to #296242.

diff --git a/propagation.py b/propagation.py
@@ -179,25 +179,25 @@
1              printer = custom_printer
2          if verbose:
3              printer( strftime('%H:%M:%S'), '** Consistency **')
4 
5          _queue = [ (constr.estimateCost(self._domains),
6 -                           constr) for constr in self._constraints ]
7 +                    id(constr), constr) for constr in self._constraints ]
8          _queue.sort()
9          _affected_constraints = {}
10          while True:
11              if not _queue:
12                  # refill the queue if some constraints have been affected
13                  _queue = [(constr.estimateCost(self._domains),
14 -                           constr) for constr in _affected_constraints]
15 +                           id(constr), constr) for constr in _affected_constraints]
16                  if not _queue:
17                      break
18                  _queue.sort()
19                  _affected_constraints.clear()
20              if verbose > 2:
21                  printer( strftime('%H:%M:%S'), 'Queue', _queue)
22 -            cost, constraint = _queue.pop(0)
23 +            cost, _, constraint = _queue.pop(0)
24              if verbose > 1:
25                  printer( strftime('%H:%M:%S'),
26                  'Trying to entail constraint', constraint, '[cost:%d]' % cost)
27              entailed = constraint.narrow(self._domains)
28              for var in constraint.affectedVariables():
diff --git a/test/test_constraints.py b/test/test_constraints.py
@@ -315,11 +315,11 @@
29      for name in dir(module):
30          obj = getattr(module, name)
31          if isclass(obj) and issubclass(obj, TestCase) and \
32                 not name.startswith('Abstract'):
33              all_cases.append(obj)
34 -    all_cases.sort()
35 +    all_cases.sort(key=lambda x: x.__name__)
36      return all_cases
37 
38  def suite(cases = None):
39      import test_constraints
40      cases = cases or get_all_cases(test_constraints)
diff --git a/test/test_distributors.py b/test/test_distributors.py
@@ -129,11 +129,11 @@
41      for name in dir(module):
42          obj = getattr(module, name)
43          if isclass(obj) and issubclass(obj, TestCase) and \
44                 not name.startswith('Abstract'):
45              all_cases.append(obj)
46 -    all_cases.sort()
47 +    all_cases.sort(key=lambda x: x.__name__)
48      return all_cases
49 
50  def suite(cases = None):
51      import test_distributors
52      cases = cases or get_all_cases(test_distributors)
diff --git a/test/test_domains.py b/test/test_domains.py
@@ -77,11 +77,11 @@
53      for name in dir(module):
54          obj = getattr(module, name)
55          if isclass(obj) and issubclass(obj, TestCase) and \
56                 not name.startswith('Abstract'):
57              all_cases.append(obj)
58 -    all_cases.sort()
59 +    all_cases.sort(key=lambda x: x.__name__)
60      return all_cases
61 
62  def suite(cases = None):
63      import test_domains
64      cases = cases or get_all_cases(test_domains)