From 5e988910002e18fc1cdaada82405edb840124fbe Mon Sep 17 00:00:00 2001 From: janga Date: Mon, 6 Feb 2017 16:06:45 +0530 Subject: [PATCH 1/4] Add type hints to axelrod_second --- axelrod/strategies/axelrod_second.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/axelrod/strategies/axelrod_second.py b/axelrod/strategies/axelrod_second.py index 94aaf3f14..e35223433 100644 --- a/axelrod/strategies/axelrod_second.py +++ b/axelrod/strategies/axelrod_second.py @@ -5,6 +5,7 @@ import random from axelrod import Actions, Player, flip_action, random_choice +from axelrod.actions import Action C, D = Actions.C, Actions.D @@ -35,7 +36,7 @@ class Champion(Player): 'manipulates_state': False } - def strategy(self, opponent): + def strategy(self, opponent: Player) -> Action: current_round = len(self.history) expected_length = self.match_attributes['length'] # Cooperate for the first 1/20-th of the game @@ -81,7 +82,7 @@ class Eatherley(Player): } @staticmethod - def strategy(opponent): + def strategy(opponent: Player) -> Action: # Cooperate on the first move if not len(opponent.history): return C @@ -118,11 +119,11 @@ class Tester(Player): 'manipulates_state': False } - def __init__(self): + def __init__(self) -> None: super().__init__() self.is_TFT = False - def strategy(self, opponent): + def strategy(self, opponent: Player) -> Action: # Defect on the first move if not opponent.history: return D From 37d6cc45f191b2f69d7281eb22c7c2eaed16b8d2 Mon Sep 17 00:00:00 2001 From: janga Date: Mon, 6 Feb 2017 16:10:18 +0530 Subject: [PATCH 2/4] Add type hints to backstabber --- axelrod/strategies/backstabber.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/axelrod/strategies/backstabber.py b/axelrod/strategies/backstabber.py index 61eb56711..e8f27f5a7 100644 --- a/axelrod/strategies/backstabber.py +++ b/axelrod/strategies/backstabber.py @@ -1,5 +1,6 @@ from axelrod import Actions, Player from axelrod.strategy_transformers import FinalTransformer +from axelrod.actions import Action C, D = Actions.C, Actions.D @@ -23,7 +24,7 @@ class BackStabber(Player): } @staticmethod - def strategy(opponent): + def strategy(opponent: Player) -> Action: if not opponent.history: return C if opponent.defections > 3: @@ -51,7 +52,7 @@ class DoubleCrosser(Player): 'manipulates_state': False } - def strategy(self, opponent): + def strategy(self, opponent: Player) -> Action: cutoff = 6 if not opponent.history: From 9279eaeb69a701171d05f0b4fec324de9b425c45 Mon Sep 17 00:00:00 2001 From: janga Date: Mon, 6 Feb 2017 16:13:34 +0530 Subject: [PATCH 3/4] Add type hints to defector --- axelrod/strategies/defector.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/axelrod/strategies/defector.py b/axelrod/strategies/defector.py index 7726699fa..4f50794c0 100644 --- a/axelrod/strategies/defector.py +++ b/axelrod/strategies/defector.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 Defector(Player): } @staticmethod - def strategy(opponent): + def strategy(opponent: Player) -> Action: return D @@ -36,7 +37,7 @@ class TrickyDefector(Player): 'manipulates_state': False } - def strategy(self, opponent): + def strategy(self, opponent: Player) -> Action: """Almost always defects, but will try to trick the opponent into cooperating. From 987a5bb329abeae039328c028409655b09f3d9b5 Mon Sep 17 00:00:00 2001 From: janga Date: Mon, 6 Feb 2017 16:16:01 +0530 Subject: [PATCH 4/4] Add files to type_tests --- type_tests.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/type_tests.sh b/type_tests.sh index b0f43caab..22365a95b 100755 --- a/type_tests.sh +++ b/type_tests.sh @@ -16,3 +16,6 @@ mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/better_an 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 +mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/axelrod_second.py +mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/backstabber.py +mypy --ignore-missing-imports --follow-imports skip axelrod/strategies/defector.py