13
13
from .action import Action
14
14
from .random_ import random_choice
15
15
from importlib import import_module
16
- from pydoc import locate
17
- import axelrod
18
16
19
17
20
18
C , D = Action .C , Action .D
@@ -61,6 +59,7 @@ def __init__(self, *args, **kwargs):
61
59
self .name_prefix = name_prefix
62
60
63
61
def __reduce__ (self ):
62
+ # Creates only the Decorator class and not the instance
64
63
return StrategyTransformerFactory , (
65
64
strategy_wrapper , name_prefix , reclassifier )
66
65
@@ -91,26 +90,18 @@ def __call__(self, PlayerClass):
91
90
except KeyError :
92
91
pass
93
92
94
- # Is the original strategy method a static method?
95
- # signature = inspect.signature(PlayerClass.strategy)
96
- # strategy_args = [p.name for p in signature.parameters.values()
97
- # if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD]
98
- # is_static = True
99
- # if len(strategy_args) > 1:
100
- # is_static = False
101
-
102
93
# Define the new strategy method, wrapping the existing method
103
94
# with `strategy_wrapper`
104
95
def strategy (self , opponent ):
105
- if strategy_wrapper != dual_wrapper :
96
+ if strategy_wrapper == dual_wrapper :
97
+ # Dummy Action for dual_wrapper.
98
+ # This is to avoid calling the strategy twice.
99
+ proposed_action = C
100
+ else :
106
101
if is_strategy_static (PlayerClass ):
107
- # static method
108
102
proposed_action = PlayerClass .strategy (opponent )
109
103
else :
110
104
proposed_action = PlayerClass .strategy (self , opponent )
111
- else :
112
- # dummy Action for dual_wrapper to avoid calling class
113
- proposed_action = C
114
105
115
106
# Apply the wrapper
116
107
return strategy_wrapper (self , opponent , proposed_action ,
@@ -151,7 +142,7 @@ def __repr__(self):
151
142
prefix = ', '
152
143
return name
153
144
154
- def new_class_reduce (self_ ):
145
+ def reduce_for_decorated_class (self_ ):
155
146
class_module = import_module (self_ .__module__ )
156
147
import_name = self_ .__class__ .__name__
157
148
if import_name in dir (class_module ):
@@ -167,7 +158,7 @@ def new_class_reduce(self_):
167
158
break
168
159
169
160
return (
170
- NewRecon (),
161
+ ReConstructor (),
171
162
(decorators , import_name , self_ .__module__ ),
172
163
self_ .__dict__
173
164
)
@@ -185,14 +176,14 @@ def new_class_reduce(self_):
185
176
"__module__" : PlayerClass .__module__ ,
186
177
"classifier" : classifier ,
187
178
"__doc__" : PlayerClass .__doc__ ,
188
- "__reduce__" : new_class_reduce ,
179
+ "__reduce__" : reduce_for_decorated_class ,
189
180
})
190
181
191
182
return new_class
192
183
return Decorator
193
184
194
185
195
- class NewRecon (object ):
186
+ class ReConstructor (object ):
196
187
def __init__ (self ):
197
188
pass
198
189
@@ -209,20 +200,6 @@ def __call__(self, decorators, import_name, module_name):
209
200
return generated_class ()
210
201
211
202
212
- # class Reconstitutor(object):
213
- # def __init__(self):
214
- #
215
- # pass
216
- #
217
- # def __call__(self, decorators, player_class, original_name):
218
- # use_class = player_class
219
- #
220
- # for decorator, args, kwargs in decorators:
221
- # use_class = decorator(*args, **kwargs)(use_class)
222
- # obj = use_class()
223
- # obj.__class__.__name__ = original_name
224
- # return obj
225
-
226
203
def compose_transformers (t1 , t2 ):
227
204
"""Compose transformers without having to invoke the first on
228
205
a PlayerClass."""
0 commit comments