From 66a2948b5524fee29a8e6b9ebbb8b9c32f6bbf99 Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Fri, 15 Dec 2017 10:08:57 +0000
Subject: [PATCH] Tidy up the typing settings

---
 .travis.yml                           |  4 ++--
 mypy.ini                              | 13 +++++++++++++
 opentech/apply/tests/test_workflow.py |  2 +-
 opentech/apply/workflow.py            |  9 +++++----
 vagrant/provision.sh                  |  2 +-
 5 files changed, 22 insertions(+), 8 deletions(-)
 create mode 100644 mypy.ini

diff --git a/.travis.yml b/.travis.yml
index e19536f96..f45e51808 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -43,8 +43,8 @@ script:
   # Type check the project
   - mypy .
 
-  # Type check the apply module
-  - mypy opentech/apply --check-untyped-defs --ignore-missing-imports
+  # Type check the project
+  - mypy .
 
   # Run system checks
   - python manage.py check
diff --git a/mypy.ini b/mypy.ini
new file mode 100644
index 000000000..6241fe330
--- /dev/null
+++ b/mypy.ini
@@ -0,0 +1,13 @@
+[mypy]
+show_column_numbers = True
+ignore_missing_imports = True
+
+[mypy-opentech.*]
+ignore_errors = True
+
+[mypy-opentech.apply.*]
+check_untyped_defs = True
+ignore_errors = False
+
+[mypy-opentech.apply.tests.*]
+# ignore_errors = True
\ No newline at end of file
diff --git a/opentech/apply/tests/test_workflow.py b/opentech/apply/tests/test_workflow.py
index 79d090c86..6548e295d 100644
--- a/opentech/apply/tests/test_workflow.py
+++ b/opentech/apply/tests/test_workflow.py
@@ -44,7 +44,7 @@ class TestStageCreation(SimpleTestCase):
 
     def test_can_iterate_through_phases(self):
         stage = StageFactory()
-        for phase, check in zip(stage, stage.phases):
+        for phase, check in zip(stage, stage.phases):  # type: ignore # spurious error
             self.assertEqual(phase, check)
 
 
diff --git a/opentech/apply/workflow.py b/opentech/apply/workflow.py
index 6476941d3..adabfc81c 100644
--- a/opentech/apply/workflow.py
+++ b/opentech/apply/workflow.py
@@ -1,4 +1,4 @@
-from typing import Iterator, Iterable, Sequence, Union
+from typing import Dict, Iterator, Iterable, Sequence, Tuple, Union
 
 from django.forms import Form
 
@@ -9,8 +9,8 @@ class Workflow:
         self.stages = stages
         self.mapping = self.build_mapping(stages)
 
-    def build_mapping(self, stages):
-        mapping = {}
+    def build_mapping(self, stages: Sequence['Stage']) -> Dict[str, Tuple[int, int]]:
+        mapping:  Dict[str, Tuple[int, int]] = {}
         for i, stage in enumerate(stages):
             for j, phase in enumerate(stage):
                 while str(phase) in mapping:
@@ -26,7 +26,7 @@ class Workflow:
         except KeyError:
             return 0, -1
 
-    def next(self, current_phase: Union['Phase', str, None]=None) -> Union['Phase', None]:
+    def next(self, current_phase: Union['Phase', str]=None) -> Union['Phase', None]:
         stage_idx, phase_idx = self.current_index(current_phase)
         try:
             return self.stages[stage_idx].phases[phase_idx + 1]
@@ -57,6 +57,7 @@ class Stage(Iterable['Phase']):
 class Phase:
     def __init__(self, name: str) -> None:
         self.name = name
+        self.stage: Union['Stage', None] = None
         self.occurance = 0
 
     def __str__(self):
diff --git a/vagrant/provision.sh b/vagrant/provision.sh
index ac208e58f..77866f4b2 100755
--- a/vagrant/provision.sh
+++ b/vagrant/provision.sh
@@ -51,6 +51,6 @@ source $VIRTUALENV_DIR/bin/activate
 export PS1="[$PROJECT_NAME \W]\\$ "
 cd $PROJECT_DIR
 
-alias djtestapply="dj test opentech.apply --keepdb; mypy opentech/apply --check-untyped-defs --ignore-missing-imports"
+alias djtestapply="dj test opentech.apply --keepdb; mypy ."
 
 EOF
-- 
GitLab