[selectors] score_entity selector now ensures an int score is returned 3.5
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 17 Sep 2009 09:49:13 +0200
branch3.5
changeset 3276 4480887772a3
parent 3273 ca78d07aaffe
child 3277 4fdb165ae3de
[selectors] score_entity selector now ensures an int score is returned
selectors.py
--- a/selectors.py	Wed Sep 16 19:26:21 2009 +0200
+++ b/selectors.py	Thu Sep 17 09:49:13 2009 +0200
@@ -960,7 +960,14 @@
     """
     def __init__(self, scorefunc, once_is_enough=False):
         super(score_entity, self).__init__(once_is_enough)
-        self.score_entity = scorefunc
+        def intscore(*args, **kwargs):
+            score = scorefunc(*args, **kwargs)
+            if not score:
+                return 0
+            if isinstance(score, (int, long)):
+                return score
+            return 1
+        self.score_entity = intscore
 
 
 # XXX DEPRECATED ##############################################################