[selectors] abstract ExpectedValueSelector now accept a set as single argument stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 05 Apr 2011 11:18:03 +0200
branchstable
changeset 7173 c6eb201d4410
parent 7172 b85396e65d8f
child 7174 4d8c103d79b6
[selectors] abstract ExpectedValueSelector now accept a set as single argument
selectors.py
--- a/selectors.py	Tue Apr 05 11:15:35 2011 +0200
+++ b/selectors.py	Tue Apr 05 11:18:03 2011 +0200
@@ -387,7 +387,9 @@
 
 class ExpectedValueSelector(Selector):
     """Take a list of expected values as initializer argument and store them
-    into the :attr:`expected` set attribute.
+    into the :attr:`expected` set attribute. You may also give a set as single
+    argument, which will be then be referenced as set of expected values,
+    allowing modification to the given set to be considered.
 
     You should implement the :meth:`_get_value(cls, req, **kwargs)` method
     which should return the value for the given context. The selector will then
@@ -395,7 +397,10 @@
     """
     def __init__(self, *expected):
         assert expected, self
-        self.expected = frozenset(expected)
+        if len(expected) == 1 and isinstance(expected[0], set):
+            self.expected = expected[0]
+        else:
+            self.expected = frozenset(expected)
 
     def __str__(self):
         return '%s(%s)' % (self.__class__.__name__,