@@ -59,9 +59,11 @@ def __init__(self, *args, **kwargs):
59
59
self .name_prefix = name_prefix
60
60
61
61
def __reduce__ (self ):
62
- # Creates only the Decorator class and not the instance
63
- return StrategyTransformerFactory , (
64
- strategy_wrapper , name_prefix , reclassifier )
62
+ return (
63
+ DecoratorReBuilder (),
64
+ (strategy_wrapper , name_prefix , reclassifier ,
65
+ self .args , self .kwargs , self .name_prefix )
66
+ )
65
67
66
68
def __call__ (self , PlayerClass ):
67
69
"""
@@ -152,13 +154,13 @@ def reduce_for_decorated_class(self_):
152
154
decorators = []
153
155
for klass in self_ .__class__ .mro ():
154
156
if hasattr (klass , 'decorator' ):
155
- decorators .append ( klass .decorator )
157
+ decorators .insert ( 0 , klass .decorator )
156
158
else :
157
159
import_name = klass .__name__
158
160
break
159
161
160
162
return (
161
- ReConstructor (),
163
+ StrategyReBuilder (),
162
164
(decorators , import_name , self_ .__module__ ),
163
165
self_ .__dict__
164
166
)
@@ -171,7 +173,7 @@ def reduce_for_decorated_class(self_):
171
173
"name" : name ,
172
174
"original_class" : PlayerClass ,
173
175
"strategy" : strategy ,
174
- "decorator" : ( self , self . args , self . kwargs ) ,
176
+ "decorator" : self ,
175
177
"__repr__" : __repr__ ,
176
178
"__module__" : PlayerClass .__module__ ,
177
179
"classifier" : classifier ,
@@ -183,7 +185,32 @@ def reduce_for_decorated_class(self_):
183
185
return Decorator
184
186
185
187
186
- class ReConstructor (object ):
188
+ def is_strategy_static (player_class ):
189
+ """
190
+
191
+ :param player_class: Any class that inherits from axelrod.Player
192
+ :return: bool
193
+ """
194
+ for klass in player_class .mro ():
195
+ method = inspect .getattr_static (klass , 'strategy' , default = None )
196
+ if method is not None :
197
+ return isinstance (method , staticmethod )
198
+
199
+
200
+ class DecoratorReBuilder (object ):
201
+ def __init__ (self ):
202
+ pass
203
+
204
+ def __call__ (self , strategy_wrapper , name_prefix , reclassifier ,
205
+ args , kwargs , instance_name_prefix ):
206
+ decorator_class = StrategyTransformerFactory (
207
+ strategy_wrapper , name_prefix , reclassifier
208
+ )
209
+ kwargs ['name_prefix' ] = instance_name_prefix
210
+ return decorator_class (* args , ** kwargs )
211
+
212
+
213
+ class StrategyReBuilder (object ):
187
214
def __init__ (self ):
188
215
pass
189
216
@@ -195,8 +222,8 @@ def __call__(self, decorators, import_name, module_name):
195
222
return import_class ()
196
223
else :
197
224
generated_class = import_class
198
- for decorator , args , kwargs in decorators :
199
- generated_class = decorator (* args , ** kwargs )( generated_class )
225
+ for decorator in decorators :
226
+ generated_class = decorator (generated_class )
200
227
return generated_class ()
201
228
202
229
@@ -288,20 +315,6 @@ def dual_wrapper(player, opponent, proposed_action):
288
315
return action .flip ()
289
316
290
317
291
- def is_strategy_static (player_class ):
292
- # signature = inspect.signature(player_class.strategy)
293
- # strategy_args = [p.name for p in signature.parameters.values()
294
- # if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD]
295
- # is_static = True
296
- # if len(strategy_args) > 1:
297
- # is_static = False
298
- # return is_static
299
- for klass in player_class .mro ():
300
- method = inspect .getattr_static (klass , 'strategy' , default = None )
301
- if method is not None :
302
- return isinstance (method , staticmethod )
303
-
304
-
305
318
DualTransformer = StrategyTransformerFactory (dual_wrapper , name_prefix = "Dual" )
306
319
307
320
0 commit comments