|
12 | 12 | from functools import partial |
13 | 13 | import sys |
14 | 14 |
|
15 | | -from characteristic import attributes |
| 15 | +import attr |
16 | 16 |
|
17 | 17 | from ._base import Effect, guard, _Box, NoPerformerFoundError |
18 | 18 | from ._sync import NotSynchronousError, sync_performer |
|
21 | 21 | import six |
22 | 22 |
|
23 | 23 |
|
24 | | -@attributes(['intent'], apply_with_init=False) |
| 24 | +@attr.s |
25 | 25 | class Stub(object): |
26 | 26 | """ |
| 27 | + DEPRECATED in favor of using :obj:`SequenceDispatcher`. |
| 28 | +
|
| 29 | +
|
27 | 30 | An intent which wraps another intent, to flag that the intent should |
28 | 31 | be automatically resolved by :func:`resolve_stub`. |
29 | 32 |
|
30 | 33 | :class:`Stub` is intentionally not performable by any default |
31 | 34 | mechanism. |
32 | 35 | """ |
33 | | - |
34 | | - def __init__(self, intent): |
35 | | - """ |
36 | | - :param intent: The intent to perform with :func:`resolve_stub`. |
37 | | - """ |
38 | | - self.intent = intent |
| 36 | + intent = attr.ib() |
39 | 37 |
|
40 | 38 |
|
41 | 39 | def ESConstant(x): |
42 | | - """Return Effect(Stub(Constant(x)))""" |
| 40 | + """DEPRECATED. Return Effect(Stub(Constant(x)))""" |
43 | 41 | return Effect(Stub(Constant(x))) |
44 | 42 |
|
45 | 43 |
|
46 | 44 | def ESError(x): |
47 | | - """Return Effect(Stub(Error(x)))""" |
| 45 | + """DEPRECATED. Return Effect(Stub(Error(x)))""" |
48 | 46 | return Effect(Stub(Error(x))) |
49 | 47 |
|
50 | 48 |
|
51 | 49 | def ESFunc(x): |
52 | | - """Return Effect(Stub(Func(x)))""" |
| 50 | + """DEPRECATED. Return Effect(Stub(Func(x)))""" |
53 | 51 | return Effect(Stub(Func(x))) |
54 | 52 |
|
55 | 53 |
|
56 | 54 | def resolve_effect(effect, result, is_error=False): |
57 | 55 | """ |
58 | 56 | Supply a result for an effect, allowing its callbacks to run. |
59 | 57 |
|
| 58 | + Note that is a pretty low-level testing utility; it's much better to use a |
| 59 | + higher-level tool like :obj:`SequenceDispatcher` in your tests. |
| 60 | +
|
60 | 61 | The return value of the last callback is returned, unless any callback |
61 | 62 | returns another Effect, in which case an Effect representing that |
62 | 63 | operation plus the remaining callbacks will be returned. |
@@ -116,6 +117,8 @@ def fail_effect(effect, exception): |
116 | 117 |
|
117 | 118 | def resolve_stub(dispatcher, effect): |
118 | 119 | """ |
| 120 | + DEPRECATED in favor of obj:`SequenceDispatcher`. |
| 121 | +
|
119 | 122 | Automatically perform an effect, if its intent is a :obj:`Stub`. |
120 | 123 |
|
121 | 124 | Note that resolve_stubs is preferred to this function, since it handles |
@@ -147,6 +150,8 @@ def resolve_stub(dispatcher, effect): |
147 | 150 |
|
148 | 151 | def resolve_stubs(dispatcher, effect): |
149 | 152 | """ |
| 153 | + DEPRECATED in favor of obj:`SequenceDispatcher`. |
| 154 | +
|
150 | 155 | Successively performs effects with resolve_stub until a non-Effect value, |
151 | 156 | or an Effect with a non-stub intent is returned, and return that value. |
152 | 157 |
|
@@ -181,6 +186,10 @@ class EQDispatcher(object): |
181 | 186 | This dispatcher looks up intents by equality and performs them by returning |
182 | 187 | an associated constant value. |
183 | 188 |
|
| 189 | + This is sometimes useful, but :obj:`SequenceDispatcher` should be |
| 190 | + preferred, since it constrains the order of effects, which is usually |
| 191 | + important. |
| 192 | +
|
184 | 193 | Users provide a mapping of intents to results, where the intents are |
185 | 194 | matched against the intents being performed with a simple equality check |
186 | 195 | (not a type check!). |
@@ -219,6 +228,10 @@ class EQFDispatcher(object): |
219 | 228 | This dispatcher looks up intents by equality and performs them by invoking |
220 | 229 | an associated function. |
221 | 230 |
|
| 231 | + This is sometimes useful, but :obj:`SequenceDispatcher` should be |
| 232 | + preferred, since it constrains the order of effects, which is usually |
| 233 | + important. |
| 234 | +
|
222 | 235 | Users provide a mapping of intents to functions, where the intents are |
223 | 236 | matched against the intents being performed with a simple equality check |
224 | 237 | (not a type check!). The functions in the mapping will be passed only the |
|
0 commit comments