diff --git a/axelrod/strategies/cooperator.py b/axelrod/strategies/cooperator.py index 2d10c1f29..4ed0cdf08 100644 --- a/axelrod/strategies/cooperator.py +++ b/axelrod/strategies/cooperator.py @@ -1,4 +1,5 @@ from axelrod import Actions, Player +from axelrod.actions import Action C, D = Actions.C, Actions.D @@ -18,7 +19,7 @@ class Cooperator(Player): } @staticmethod - def strategy(opponent): + def strategy(opponent: Player) -> Action: return C @@ -37,7 +38,7 @@ class TrickyCooperator(Player): } @staticmethod - def strategy(opponent): + def strategy(opponent: Player) -> Action: """Almost always cooperates, but will try to trick the opponent by defecting. Defect once in a while in order to get a better payout, when the opponent diff --git a/axelrod/strategies/cycler.py b/axelrod/strategies/cycler.py index 730313dfc..3acde1841 100644 --- a/axelrod/strategies/cycler.py +++ b/axelrod/strategies/cycler.py @@ -1,4 +1,5 @@ from axelrod import Actions, Player, init_args +from axelrod.actions import Action import copy @@ -20,12 +21,12 @@ class AntiCycler(Player): 'manipulates_state': False } - def __init__(self): + def __init__(self) -> None: super().__init__() self.cycle_length = 1 self.cycle_counter = 0 - def strategy(self, opponent): + def strategy(self, opponent: Player) -> Action: if self.cycle_counter < self.cycle_length: self.cycle_counter += 1 return Actions.C @@ -55,7 +56,7 @@ class Cycler(Player): } @init_args - def __init__(self, cycle="CCD"): + def __init__(self, cycle="CCD") -> None: """This strategy will repeat the parameter `cycle` endlessly, e.g. C C D C C D C C D ... @@ -71,7 +72,7 @@ def __init__(self, cycle="CCD"): self.name = "Cycler {}".format(cycle) self.classifier['memory_depth'] = len(cycle) - 1 - def strategy(self, opponent): + def strategy(self, opponent: Player) -> Action: curent_round = len(self.history) index = curent_round % len(self.cycle) return self.cycle[index] @@ -84,7 +85,7 @@ class CyclerDC(Cycler): classifier['memory_depth'] = 1 @init_args - def __init__(self, cycle="DC"): + def __init__(self, cycle="DC") -> None: super().__init__(cycle=cycle) @@ -95,7 +96,7 @@ class CyclerCCD(Cycler): classifier['memory_depth'] = 2 @init_args - def __init__(self, cycle="CCD"): + def __init__(self, cycle="CCD") -> None: super().__init__(cycle=cycle) @@ -106,7 +107,7 @@ class CyclerDDC(Cycler): classifier['memory_depth'] = 2 @init_args - def __init__(self, cycle="DDC"): + def __init__(self, cycle="DDC") -> None: super().__init__(cycle=cycle) @@ -117,7 +118,7 @@ class CyclerCCCD(Cycler): classifier['memory_depth'] = 3 @init_args - def __init__(self, cycle="CCCD"): + def __init__(self, cycle="CCCD") -> None: super().__init__(cycle=cycle) @@ -128,7 +129,7 @@ class CyclerCCCCCD(Cycler): classifier['memory_depth'] = 5 @init_args - def __init__(self, cycle="CCCCCD"): + def __init__(self, cycle="CCCCCD") -> None: super().__init__(cycle=cycle) @@ -139,5 +140,5 @@ class CyclerCCCDCD(Cycler): classifier['memory_depth'] = 5 @init_args - def __init__(self, cycle="CCCDCD"): + def __init__(self, cycle="CCCDCD") -> None: super().__init__(cycle=cycle) diff --git a/axelrod/strategies/darwin.py b/axelrod/strategies/darwin.py index 431f9383b..1d76ad815 100644 --- a/axelrod/strategies/darwin.py +++ b/axelrod/strategies/darwin.py @@ -1,5 +1,8 @@ import inspect from axelrod import Actions, Player +from axelrod.actions import Action + +from typing import List C, D = Actions.C, Actions.D @@ -35,14 +38,14 @@ class Darwin(Player): genome = [C] valid_callers = ["play"] # What functions may invoke our strategy. - def __init__(self): + def __init__(self) -> None: super().__init__() self.response = Darwin.genome[0] def receive_match_attributes(self): self.outcomes = self.match_attributes["game"].scores - def strategy(self, opponent): + def strategy(self, opponent: Player) -> Action: # Frustrate psychics and ensure that simulated rounds # do not influence genome. if inspect.stack()[1][3] not in Darwin.valid_callers: diff --git a/type_tests.sh b/type_tests.sh index 9cabada32..c06ae1cbd 100755 --- a/type_tests.sh +++ b/type_tests.sh @@ -12,4 +12,6 @@ mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/appeaser. mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/averagecopier.py mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/forgiver.py mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/better_and_better.py - +mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/darwin.py +mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/cycler.py +mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/cooperator.py