1616
1717
1818from __future__ import print_function , absolute_import
19- from characteristic import attributes
19+
20+ import attr
2021
2122from ._base import Effect
2223from ._sync import sync_performer
2324from ._dispatcher import TypeDispatcher
2425
2526
26- @attributes ([ 'effects' ], apply_with_init = False , apply_immutable = True )
27+ @attr . s
2728class ParallelEffects (object ):
2829 """
2930 An effect intent that asks for a number of effects to be run in parallel,
@@ -40,12 +41,11 @@ class ParallelEffects(object):
4041
4142 Performers of this intent must fail with a :obj:`FirstError` exception when
4243 any child effect fails, representing the first error.
44+
45+ :param effects: Effects to be performed in parallel.
4346 """
44- def __init__ (self , effects ):
45- """
46- :param effects: Effects which should be performed in parallel.
47- """
48- self .effects = effects
47+
48+ effects = attr .ib ()
4949
5050
5151def parallel (effects ):
@@ -83,40 +83,41 @@ def parallel_all_errors(effects):
8383 return Effect (ParallelEffects (list (effects )))
8484
8585
86- @attributes ([ 'exc_info' , 'index' ])
86+ @attr . s
8787class FirstError (Exception ):
8888 """
8989 One of the effects in a :obj:`ParallelEffects` resulted in an error. This
9090 represents the first such error that occurred.
9191 """
92+ exc_info = attr .ib ()
93+ index = attr .ib ()
94+
9295 def __str__ (self ):
9396 return '(index=%s) %s: %s' % (
9497 self .index , self .exc_info [0 ].__name__ , self .exc_info [1 ])
9598
9699
97- @attributes ([ 'delay' ], apply_with_init = False , apply_immutable = True )
100+ @attr . s
98101class Delay (object ):
99102 """
100103 An intent which represents a delay in time.
101104
102105 When performed, the specified delay will pass and then the effect will
103106 result in None.
107+
108+ :param float delay: The number of seconds to delay.
104109 """
105- def __init__ (self , delay ):
106- """
107- :param float delay: The number of seconds to delay.
108- """
109- self .delay = delay
110+ delay = attr .ib ()
110111
111112
112- @attributes ([ 'result' ], apply_with_init = False , apply_immutable = True )
113+ @attr . s
113114class Constant (object ):
114- """An intent that returns a pre-specified result when performed."""
115- def __init__ ( self , result ):
116- """
117- :param result: The object which the Effect should result in.
118- """
119- self . result = result
115+ """
116+ An intent that returns a pre-specified result when performed.
117+
118+ :param result: The object which the Effect will result in.
119+ """
120+ result = attr . ib ()
120121
121122
122123@sync_performer
@@ -125,11 +126,14 @@ def perform_constant(dispatcher, intent):
125126 return intent .result
126127
127128
128- @attributes ([ 'exception' ], apply_with_init = False , apply_immutable = True )
129+ @attr . s
129130class Error (object ):
130- """An intent that raises a pre-specified exception when performed."""
131- def __init__ (self , exception ):
132- self .exception = exception
131+ """
132+ An intent that raises a pre-specified exception when performed.
133+
134+ :param BaseException exception: Exception instance to raise.
135+ """
136+ exception = attr .ib ()
133137
134138
135139@sync_performer
@@ -138,7 +142,7 @@ def perform_error(dispatcher, intent):
138142 raise intent .exception
139143
140144
141- @attributes ([ 'func' ], apply_with_init = False , apply_immutable = True )
145+ @attr . s
142146class Func (object ):
143147 """
144148 An intent that returns the result of the specified function.
@@ -157,12 +161,10 @@ class Func(object):
157161 intents as inert objects with public attributes of simple data. However,
158162 this is useful for integrating wih "legacy" side-effecting code in a quick
159163 way.
164+
165+ :param func: The function to call when this intent is performed.
160166 """
161- def __init__ (self , func ):
162- """
163- :param func: The function to call when this intent is performed.
164- """
165- self .func = func
167+ func = attr .ib ()
166168
167169
168170@sync_performer
0 commit comments