-
Notifications
You must be signed in to change notification settings - Fork 269
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
|
@@ -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 | ||
---------- | ||
|
@@ -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 | ||
---------- | ||
|
@@ -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: | ||
"""Validate a proposed dictionary key. | ||
|
||
Parameters | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
"""Load a previously saved cache into the dictionary. | ||
|
||
Parameters | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool
instead ofboolean