Skip to content

Commit ede888c

Browse files
meatballsmarcharper
authored andcommitted
Format all code using black
1 parent f375af3 commit ede888c

File tree

162 files changed

+11163
-8342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+11163
-8342
lines changed

axelrod/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
from .plot import Plot
1010
from .game import DefaultGame, Game
1111
from .player import (
12-
get_state_distribution_from_history, is_basic, obey_axelrod,
13-
update_history, update_state_distribution, Player)
12+
get_state_distribution_from_history,
13+
is_basic,
14+
obey_axelrod,
15+
update_history,
16+
update_state_distribution,
17+
Player,
18+
)
1419
from .mock_player import MockPlayer
1520
from .match import Match
1621
from .moran import MoranProcess, ApproximateMoranProcess
@@ -21,4 +26,3 @@
2126
from .result_set import ResultSet
2227
from .ecosystem import Ecosystem
2328
from .fingerprint import AshlockFingerprint, TransitiveFingerprint
24-

axelrod/_strategy_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def inspect_strategy(inspector, opponent):
6666
Action
6767
The action that would be taken by the opponent.
6868
"""
69-
if hasattr(opponent, 'foil_strategy_inspection'):
69+
if hasattr(opponent, "foil_strategy_inspection"):
7070
return opponent.foil_strategy_inspection()
7171
else:
7272
return opponent.strategy(inspector)

axelrod/action.py

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

1313
class UnknownActionError(ValueError):
1414
"""Error indicating an unknown action was used."""
15+
1516
def __init__(self, *args):
1617
super(UnknownActionError, self).__init__(*args)
1718

@@ -30,10 +31,10 @@ def __bool__(self):
3031
return bool(self.value)
3132

3233
def __repr__(self):
33-
return '{}'.format(self.name)
34+
return "{}".format(self.name)
3435

3536
def __str__(self):
36-
return '{}'.format(self.name)
37+
return "{}".format(self.name)
3738

3839
def flip(self):
3940
"""Returns the opposite Action."""
@@ -61,9 +62,9 @@ def from_char(cls, character):
6162
UnknownActionError
6263
If the input string is not 'C' or 'D'
6364
"""
64-
if character == 'C':
65+
if character == "C":
6566
return cls.C
66-
if character == 'D':
67+
if character == "D":
6768
return cls.D
6869
raise UnknownActionError('Character must be "C" or "D".')
6970

axelrod/deterministic_cache.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ def _is_valid_key(key: CachePlayerKey) -> bool:
5353
return False
5454

5555
if not (
56-
isinstance(key[0], Player) and
57-
isinstance(key[1], Player) and
58-
isinstance(key[2], int)
56+
isinstance(key[0], Player)
57+
and isinstance(key[1], Player)
58+
and isinstance(key[2], int)
5959
):
6060
return False
6161

62-
if key[0].classifier['stochastic'] or key[1].classifier['stochastic']:
62+
if key[0].classifier["stochastic"] or key[1].classifier["stochastic"]:
6363
return False
6464

6565
return True
@@ -106,7 +106,7 @@ class DeterministicCache(UserDict):
106106
methods to save/load the cache to/from a file.
107107
"""
108108

109-
def __init__(self, file_name: str=None) -> None:
109+
def __init__(self, file_name: str = None) -> None:
110110
"""Initialize a new cache.
111111
112112
Parameters
@@ -131,16 +131,18 @@ def __contains__(self, key):
131131
def __setitem__(self, key: CachePlayerKey, value):
132132
"""Validate the key and value before setting them."""
133133
if not self.mutable:
134-
raise ValueError('Cannot update cache unless mutable is True.')
134+
raise ValueError("Cannot update cache unless mutable is True.")
135135

136136
if not _is_valid_key(key):
137137
raise ValueError(
138138
"Key must be a tuple of 2 deterministic axelrod Player classes "
139-
"and an integer")
139+
"and an integer"
140+
)
140141

141142
if not _is_valid_value(value):
142143
raise ValueError(
143-
'Value must be a list with length equal to turns attribute')
144+
"Value must be a list with length equal to turns attribute"
145+
)
144146

145147
super().__setitem__(_key_transform(key), value)
146148

@@ -152,7 +154,7 @@ def save(self, file_name: str) -> bool:
152154
file_name : string
153155
File path to which the cache should be saved
154156
"""
155-
with open(file_name, 'wb') as io:
157+
with open(file_name, "wb") as io:
156158
pickle.dump(self.data, io)
157159
return True
158160

@@ -164,13 +166,14 @@ def load(self, file_name: str) -> bool:
164166
file_name : string
165167
Path to a previously saved cache file
166168
"""
167-
with open(file_name, 'rb') as io:
169+
with open(file_name, "rb") as io:
168170
data = pickle.load(io)
169171

170172
if isinstance(data, dict):
171173
self.data = data
172174
else:
173175
raise ValueError(
174176
"Cache file exists but is not the correct format. "
175-
"Try deleting and re-building the cache file.")
177+
"Try deleting and re-building the cache file."
178+
)
176179
return True

axelrod/ecosystem.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ class Ecosystem(object):
2727
The number of players
2828
"""
2929

30-
def __init__(self, results: ResultSet,
31-
fitness: Callable[[float], float] = None,
32-
population: List[int] = None) -> None:
30+
def __init__(
31+
self,
32+
results: ResultSet,
33+
fitness: Callable[[float], float] = None,
34+
population: List[int] = None,
35+
) -> None:
3336
"""Create a new ecosystem.
3437
3538
Parameters
@@ -58,16 +61,19 @@ def __init__(self, results: ResultSet,
5861
if population:
5962
if min(population) < 0:
6063
raise TypeError(
61-
"Minimum value of population vector must be non-negative")
64+
"Minimum value of population vector must be non-negative"
65+
)
6266
elif len(population) != self.num_players:
6367
raise TypeError(
64-
"Population vector must be same size as number of players")
68+
"Population vector must be same size as number of players"
69+
)
6570
else:
6671
norm = sum(population)
6772
self.population_sizes = [[p / norm for p in population]]
6873
else:
6974
self.population_sizes = [
70-
[1 / self.num_players for _ in range(self.num_players)]]
75+
[1 / self.num_players for _ in range(self.num_players)]
76+
]
7177

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

axelrod/eigen.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def _normalise(nvec: numpy.ndarray) -> numpy.ndarray:
1313
"""Normalises the given numpy array."""
14-
with numpy.errstate(invalid='ignore'):
14+
with numpy.errstate(invalid="ignore"):
1515
result = nvec / numpy.sqrt(numpy.dot(nvec, nvec))
1616
return result
1717

@@ -45,8 +45,9 @@ def _power_iteration(mat: numpy.matrix, initial: numpy.ndarray) -> numpy.ndarray
4545
yield vec
4646

4747

48-
def principal_eigenvector(mat: numpy.matrix, maximum_iterations=1000,
49-
max_error=1e-3) -> Tuple[numpy.ndarray, float]:
48+
def principal_eigenvector(
49+
mat: numpy.matrix, maximum_iterations=1000, max_error=1e-3
50+
) -> Tuple[numpy.ndarray, float]:
5051
"""
5152
Computes the (normalised) principal eigenvector of the given matrix.
5253
@@ -75,7 +76,7 @@ def principal_eigenvector(mat: numpy.matrix, maximum_iterations=1000,
7576

7677
# Power iteration
7778
if not maximum_iterations:
78-
maximum_iterations = float('inf')
79+
maximum_iterations = float("inf")
7980
last = initial
8081
for i, vector in enumerate(_power_iteration(mat, initial=initial)):
8182
if i > maximum_iterations:
@@ -84,8 +85,7 @@ def principal_eigenvector(mat: numpy.matrix, maximum_iterations=1000,
8485
break
8586
last = vector
8687
# Compute the eigenvalue (Rayleigh quotient)
87-
eigenvalue = numpy.dot(
88-
numpy.dot(mat_, vector), vector) / numpy.dot(vector, vector)
88+
eigenvalue = numpy.dot(numpy.dot(mat_, vector), vector) / numpy.dot(vector, vector)
8989
# Liberate the eigenvalue from numpy
9090
eigenvalue = float(eigenvalue)
9191
return vector, eigenvalue

0 commit comments

Comments
 (0)