Skip to content

Commit 0aafa05

Browse files
committed
EQDispatcher pretty much requires that everything be hashable
1 parent f06ec0f commit 0aafa05

5 files changed

Lines changed: 20 additions & 4 deletions

File tree

effect/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, intent, callbacks=None):
2626
"""
2727
self.intent = intent
2828
if callbacks is None:
29-
callbacks = []
29+
callbacks = ()
3030
self.callbacks = callbacks
3131

3232
def on(self, success=None, error=None):
@@ -44,7 +44,7 @@ def on(self, success=None, error=None):
4444
:obj:`Effect` will be passed to the next callback.
4545
"""
4646
return Effect(self.intent,
47-
callbacks=self.callbacks + [(success, error)])
47+
callbacks=self.callbacks + ((success, error),))
4848

4949

5050
class _Box(object):

effect/_intents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, effects):
4545
"""
4646
:param effects: Effects which should be performed in parallel.
4747
"""
48-
self.effects = effects
48+
self.effects = tuple(effects)
4949

5050

5151
def parallel(effects):

effect/test_base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,14 @@ def get_stack(_):
288288
perform(func_dispatcher, eff)
289289
boxes[0].succeed('foo')
290290
self.assertEqual(calls[0], calls[1])
291+
292+
293+
class HashTests(TestCase):
294+
"""Tests for hashing of effects."""
295+
296+
def test_hashable(self):
297+
"""
298+
Effects are hashable, despite the fact that the callbacks are stored as
299+
a list.
300+
"""
301+
hash(Effect(None))

effect/test_intents.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Constant, perform_constant,
1111
Error, perform_error,
1212
Func, perform_func,
13+
parallel,
1314
FirstError)
1415

1516

@@ -58,3 +59,7 @@ def test_first_error_str(self):
5859
self.assertEqual(
5960
str(fe),
6061
'(index=150) ValueError: foo')
62+
63+
def test_hashable(self):
64+
"""ParallelIntents are hashable."""
65+
hash(parallel([Effect(None), Effect(None)]))

effect/test_testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_non_test_intent(self):
164164
eff = ESConstant("foo").on(success=lambda r: bare_effect)
165165
result_eff = resolve_stubs(base_dispatcher, eff)
166166
self.assertIs(result_eff.intent, bare_effect.intent)
167-
self.assertEqual(result_eff.callbacks, [])
167+
self.assertEqual(result_eff.callbacks, ())
168168

169169
def test_type_error(self):
170170
"""

0 commit comments

Comments
 (0)