Skip to content

Commit 6d136e1

Browse files
Merge pull request #831 from janga1997/typeHint-loadData
Add type hints to load_data
2 parents d278a6e + 2990e46 commit 6d136e1

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

axelrod/load_data_.py

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

3-
4-
def load_file(filename, directory):
4+
def load_file(filename: str, directory: str) -> List[List[str]]:
55
"""Loads a data file stored in the Axelrod library's data subdirectory,
66
likely for parameters for a strategy."""
77
path = '/'.join((directory, filename))
8-
data = pkg_resources.resource_string(__name__, path)
9-
data = data.decode('UTF-8', 'replace')
8+
data_bytes = pkg_resources.resource_string(__name__, path)
9+
data = data_bytes.decode('UTF-8', 'replace')
1010
rows = []
1111
for line in data.split('\n'):
1212
if line.startswith('#') or len(line) == 0:
@@ -16,7 +16,7 @@ def load_file(filename, directory):
1616
return rows
1717

1818

19-
def load_weights(filename="ann_weights.csv", directory="data"):
19+
def load_weights(filename: str ="ann_weights.csv", directory: str ="data") -> Dict[str, Tuple[int, int, List[float]]]:
2020
"""Load Neural Network Weights."""
2121
rows = load_file(filename, directory)
2222
d = dict()
@@ -28,7 +28,6 @@ def load_weights(filename="ann_weights.csv", directory="data"):
2828
d[name] = (num_features, num_hidden, weights)
2929
return d
3030

31-
3231
def load_pso_tables(filename="pso_gambler.csv", directory="data"):
3332
"""Load lookup tables."""
3433
rows = load_file(filename, directory)

0 commit comments

Comments
 (0)