Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Type Hints in Deterministic Cache #828

Merged
merged 4 commits into from
Jan 30, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions axelrod/deterministic_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import UserDict
import pickle
from typing import Tuple

from axelrod import Player

Expand Down Expand Up @@ -29,7 +30,7 @@ class DeterministicCache(UserDict):
methods to save/load the cache to/from a file.
"""

def __init__(self, file_name=None):
def __init__(self, file_name: str=None):
"""
Parameters
----------
Expand All @@ -42,7 +43,7 @@ def __init__(self, file_name=None):
self.load(file_name)

@staticmethod
def _key_transform(key):
def _key_transform(key: Tuple[str, str, int]):
"""
Parameters
----------
Expand Down Expand Up @@ -78,7 +79,7 @@ def __setitem__(self, key, value):
super().__setitem__(self._key_transform(key), value)

@staticmethod
def _is_valid_key(key):
def _is_valid_key(key) -> boolean:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool instead of boolean

"""Validate a proposed dictionary key.

Parameters
Expand Down Expand Up @@ -116,7 +117,7 @@ def _is_valid_key(key):
return True

@staticmethod
def _is_valid_value(value):
def _is_valid_value(value) -> boolean:
"""Validate a proposed dictionary value.

Parameters
Expand All @@ -133,7 +134,7 @@ def _is_valid_value(value):

return True

def save(self, file_name):
def save(self, file_name: str):
"""Serialise the cache dictionary to a file.

Parameters
Expand All @@ -145,7 +146,7 @@ def save(self, file_name):
pickle.dump(self.data, io)
return True

def load(self, file_name):
def load(self, file_name: str) -> boolean:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to bool rather than boolean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""Load a previously saved cache into the dictionary.

Parameters
Expand Down