[predicates] fix predicates that erroneously evaluate the entity passed as a parameter as a boolean, instead of testing its existence in the keyword arguments -using the kwargs.get('entity') idiom instead of 'entity' in kwargs or similar- ; closes #2424288 stable
authorFlorent Cayré <florent.cayre@logilab.fr>
Fri, 20 Jul 2012 11:42:59 +0200
branchstable
changeset 8481 ff3b163f52e9
parent 8480 086cff6a306a
child 8482 0044a29ea118
[predicates] fix predicates that erroneously evaluate the entity passed as a parameter as a boolean, instead of testing its existence in the keyword arguments -using the kwargs.get('entity') idiom instead of 'entity' in kwargs or similar- ; closes #2424288
predicates.py
--- a/predicates.py	Fri Jul 20 10:25:55 2012 +0200
+++ b/predicates.py	Fri Jul 20 11:42:59 2012 +0200
@@ -352,12 +352,12 @@
     """
 
     def __call__(self, cls, req, rset=None, row=None, col=0, accept_none=None,
-                 **kwargs):
-        if not rset and not kwargs.get('entity'):
+                 entity=None, **kwargs):
+        if not rset and entity is None:
             return 0
         score = 0
-        if kwargs.get('entity'):
-            score = self.score_entity(kwargs['entity'])
+        if entity is not None:
+            score = self.score_entity(entity)
         elif row is None:
             col = col or 0
             if accept_none is None:
@@ -1076,9 +1076,9 @@
 
     # don't use EntityPredicate.__call__ but this optimized implementation to
     # avoid considering each entity when it's not necessary
-    def __call__(self, cls, req, rset=None, row=None, col=0, **kwargs):
-        if kwargs.get('entity'):
-            return self.score_entity(kwargs['entity'])
+    def __call__(self, cls, req, rset=None, row=None, col=0, entity=None, **kwargs):
+        if entity is not None:
+            return self.score_entity(entity)
         if rset is None:
             return 0
         if row is None: