Skip to content

Commit f80072f

Browse files
marcharperdrvinceknight
authored andcommitted
Various PEP8 and style fixes
1 parent 5188f9d commit f80072f

File tree

9 files changed

+111
-95
lines changed

9 files changed

+111
-95
lines changed

axelrod/ecosystem.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from axelrod.result_set import ResultSet
22
import random
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from typing import List, Any, Union
55
import numpy as np
66
import tqdm
7-
import axelrod as axl
87

8+
import axelrod as axl
99
from axelrod import on_windows, Player
1010
from axelrod.strategy_transformers import JossAnnTransformer, DualTransformer
1111
from axelrod.interaction_utils import (

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from collections import defaultdict
2+
from itertools import cycle
3+
from typing import List, Tuple
14
import warnings
5+
26
from axelrod.actions import Actions, Action
37
from axelrod.player import Player, update_history, update_state_distribution
4-
from collections import defaultdict
5-
from itertools import cycle
68

7-
from typing import List, Tuple
89

910
C, D = Actions.C, Actions.D
1011

axelrod/player.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from collections import defaultdict
2-
from functools import wraps
3-
import random
42
import copy
53
import inspect
4+
import itertools
5+
import random
66
import types
7+
from typing import Dict, Any
8+
79
import numpy as np
8-
import itertools
910

10-
from axelrod.actions import Actions, flip_action, Action
11+
from axelrod.actions import Actions, flip_action
1112
from .game import DefaultGame
1213

13-
from typing import Dict, Any
1414

1515
C, D = Actions.C, Actions.D
1616

@@ -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').

0 commit comments

Comments
 (0)