Skip to content

Commit a797167

Browse files
authored
Merge pull request #1037 from Axelrod-Python/pep8
Various PEP8 and style fixes
2 parents 5188f9d + 19e5899 commit a797167

36 files changed

+405
-430
lines changed

axelrod/deterministic_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from collections import UserDict
22
import pickle
3-
from typing import List, Tuple
43

54
from .actions import Action
65
from .player import Player
76

7+
from typing import List, Tuple
88

99
CachePlayerKey = Tuple[Player, Player, int]
1010
CacheKey = Tuple[str, str, int]

axelrod/ecosystem.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from axelrod.result_set import ResultSet
21
import random
2+
from axelrod.result_set import ResultSet
33
from typing import List, Callable
4+
5+
46
class Ecosystem(object):
57
"""Create an ecosystem based on the payoff matrix from an Axelrod
68
tournament."""
@@ -21,14 +23,17 @@ def __init__(self, results: ResultSet, fitness: Callable[[float], float] =None,
2123
# values.
2224
if population:
2325
if min(population) < 0:
24-
raise TypeError("Minimum value of population vector must be non-negative")
26+
raise TypeError(
27+
"Minimum value of population vector must be non-negative")
2528
elif len(population) != self.nplayers:
26-
raise TypeError("Population vector must be same size as number of players")
29+
raise TypeError(
30+
"Population vector must be same size as number of players")
2731
else:
2832
norm = sum(population)
2933
self.population_sizes = [[p / norm for p in population]]
3034
else:
31-
self.population_sizes = [[1 / self.nplayers for i in range(self.nplayers)]]
35+
self.population_sizes = [
36+
[1 / self.nplayers for _ in range(self.nplayers)]]
3237

3338
# This function is quite arbitrary and probably only influences the
3439
# kinetics for the current code.

axelrod/fingerprint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from collections import namedtuple
22
from tempfile import NamedTemporaryFile
33
import matplotlib.pyplot as plt
4-
from typing import List, Any, Union
54
import numpy as np
65
import tqdm
7-
import axelrod as axl
86

7+
import axelrod as axl
98
from axelrod import on_windows, Player
109
from axelrod.strategy_transformers import JossAnnTransformer, DualTransformer
1110
from axelrod.interaction_utils import (
1211
compute_final_score_per_turn, read_interactions_from_file)
1312

13+
from typing import List, Any, Union
1414

1515
Point = namedtuple('Point', 'x y')
1616

axelrod/interaction_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"""
1010
from collections import Counter
1111
import csv
12+
import tqdm
1213

1314
from axelrod.actions import Actions
1415
from .game import Game
1516

16-
import tqdm
1717

1818
C, D = Actions.C, Actions.D
1919

axelrod/load_data_.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pkg_resources
2-
from typing import List, Dict, Tuple, Union
2+
from typing import List, Dict, Tuple
3+
34

45
def load_file(filename: str, directory: str) -> List[List[str]]:
56
"""Loads a data file stored in the Axelrod library's data subdirectory,
@@ -28,6 +29,7 @@ def load_weights(filename: str ="ann_weights.csv", directory: str ="data") -> Di
2829
d[name] = (num_features, num_hidden, weights)
2930
return d
3031

32+
3133
def load_pso_tables(filename="pso_gambler.csv", directory="data"):
3234
"""Load lookup tables."""
3335
rows = load_file(filename, directory)

axelrod/mock_player.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from collections import defaultdict
2+
from itertools import cycle
13
import warnings
4+
25
from axelrod.actions import Actions, Action
36
from axelrod.player import Player, update_history, update_state_distribution
4-
from collections import defaultdict
5-
from itertools import cycle
67

78
from typing import List, Tuple
89

axelrod/player.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from collections import defaultdict
2-
from functools import wraps
3-
import random
42
import copy
53
import inspect
6-
import types
7-
import numpy as np
84
import itertools
5+
import random
6+
7+
import numpy as np
98

10-
from axelrod.actions import Actions, flip_action, Action
9+
from axelrod.actions import Actions, flip_action
1110
from .game import DefaultGame
1211

12+
import types
1313
from typing import Dict, Any
1414

1515
C, D = Actions.C, Actions.D
@@ -97,12 +97,14 @@ def __new__(cls, *args, **kwargs):
9797
@classmethod
9898
def init_params(cls, *args, **kwargs):
9999
"""
100-
Return a dictionary containing the init parameters of a strategy (without 'self').
100+
Return a dictionary containing the init parameters of a strategy
101+
(without 'self').
101102
Use *args and *kwargs as value if specified
102103
and complete the rest with the default values.
103104
"""
104105
sig = inspect.signature(cls.__init__)
105-
# the 'self' parameter needs to be removed or the first *args will be assigned to it
106+
# The 'self' parameter needs to be removed or the first *args will be
107+
# assigned to it
106108
self_param = sig.parameters.get('self')
107109
new_params = list(sig.parameters.values())
108110
new_params.remove(self_param)
@@ -125,7 +127,6 @@ def __init__(self):
125127
self.state_distribution = defaultdict(int)
126128
self.set_match_attributes()
127129

128-
129130
def __eq__(self, other):
130131
"""
131132
Test if two players are equal.
@@ -149,7 +150,6 @@ def __eq__(self, other):
149150
generator, original_value = itertools.tee(value)
150151
other_generator, original_other_value = itertools.tee(other_value)
151152

152-
153153
if isinstance(value, types.GeneratorType):
154154
setattr(self, attribute,
155155
(ele for ele in original_value))
@@ -171,14 +171,13 @@ def __eq__(self, other):
171171
# Code for a strange edge case where each strategy points at each
172172
# other
173173
elif (value is other and other_value is self):
174-
pass
174+
pass
175175

176176
else:
177177
if value != other_value:
178178
return False
179179
return True
180180

181-
182181
def receive_match_attributes(self):
183182
# Overwrite this function if your strategy needs
184183
# to make use of match_attributes such as

axelrod/strategies/_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ExampleStrategy(Player):
7171
7272
Parameters
7373
----------
74-
strategy : a descendant class of axelrod.Player
74+
player: a descendant class of axelrod.Player
7575
classifier_key: string
7676
Defining which entry from the strategy's classifier dict is to be
7777
tested (e.g. 'makes_use_of').

axelrod/strategies/adaptive.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from axelrod.actions import Actions, Action
22
from axelrod.player import Player
3-
import axelrod
43

54
from typing import List
65

axelrod/strategies/ann.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
import numpy as np
88

9-
from typing import List, Tuple
10-
119
from axelrod.actions import Actions, Action
1210
from axelrod.player import Player
1311
from axelrod.load_data_ import load_weights
1412

13+
from typing import List, Tuple
14+
1515
C, D = Actions.C, Actions.D
1616
nn_weights = load_weights()
1717

@@ -69,8 +69,6 @@ def compute_features(player: Player, opponent: Player) -> List[int]:
6969
opponent_previous2_c = 0
7070
opponent_previous2_d = 0
7171

72-
73-
7472
else:
7573
opponent_first_c = 1 if opponent.history[0] == C else 0
7674
opponent_first_d = 1 if opponent.history[0] == D else 0
@@ -179,7 +177,8 @@ class ANN(Player):
179177
'long_run_time': False
180178
}
181179

182-
def __init__(self, weights: List[float], num_features: int, num_hidden: int) -> None:
180+
def __init__(self, weights: List[float], num_features: int,
181+
num_hidden: int) -> None:
183182
super().__init__()
184183
(i2h, h2o, bias) = split_weights(weights, num_features, num_hidden)
185184
self.input_to_hidden_layer_weights = np.matrix(i2h)

0 commit comments

Comments
 (0)