@@ -177,23 +177,29 @@ class EQDispatcher(object):
177177 matched against the intents being performed with a simple equality check
178178 (not a type check!).
179179
180+ The mapping must be provided as a sequence of two-tuples. We don't use a
181+ dict because we don't want to require that the intents be hashable (in
182+ practice a lot of them aren't, and it's a pain to require it). If you want
183+ to construct your mapping as a dict, you can, just pass in the result of
184+ ``d.items()``.
185+
180186 e.g.::
181187
182- >>> sync_perform(EQDispatcher({ MyIntent(1, 2): 'the-result'} ),
188+ >>> sync_perform(EQDispatcher([( MyIntent(1, 2), 'the-result')] ),
183189 ... Effect(MyIntent(1, 2)))
184190 'the-result'
185191
186192 assuming MyIntent supports ``__eq__`` by value.
187193 """
188194 def __init__ (self , mapping ):
189195 """
190- :param mapping: Mapping of intents to results .
196+ :param list mapping: A sequence of tuples of (intent, result) .
191197 """
192198 self .mapping = mapping
193199
194200 def __call__ (self , intent ):
195201 # Avoid hashing, because a lot of intents aren't hashable.
196- for k , v in self .mapping . items () :
202+ for k , v in self .mapping :
197203 if k == intent :
198204 return sync_performer (lambda d , i : v )
199205
@@ -210,24 +216,30 @@ class EQFDispatcher(object):
210216 (not a type check!). The functions in the mapping will be passed only the
211217 intent and are expected to return the result or raise an exception.
212218
219+ The mapping must be provided as a sequence of two-tuples. We don't use a
220+ dict because we don't want to require that the intents be hashable (in
221+ practice a lot of them aren't, and it's a pain to require it). If you want
222+ to construct your mapping as a dict, you can, just pass in the result of
223+ ``d.items()``.
224+
213225 e.g.::
214226
215227 >>> sync_perform(
216- ... EQFDispatcher({
217- ... MyIntent(1, 2): lambda i: 'the-result'} ),
228+ ... EQFDispatcher([(
229+ ... MyIntent(1, 2), lambda i: 'the-result')] ),
218230 ... Effect(MyIntent(1, 2)))
219231 'the-result'
220232
221233 assuming MyIntent supports ``__eq__`` by value.
222234 """
223235 def __init__ (self , mapping ):
224236 """
225- :param mapping: Mapping of intents to results .
237+ :param list mapping: A sequence of two-tuples of (intent, function) .
226238 """
227239 self .mapping = mapping
228240
229241 def __call__ (self , intent ):
230242 # Avoid hashing, because a lot of intents aren't hashable.
231- for k , v in self .mapping . items () :
243+ for k , v in self .mapping :
232244 if k == intent :
233245 return sync_performer (lambda d , i : v (i ))
0 commit comments