From 422f8ddca869d835612771e53362c4f48a1f868f Mon Sep 17 00:00:00 2001
From: Mariana Ulaieva <mulaieva@redhat.com>
Date: Apr 28 2020 10:35:22 +0000
Subject: [PATCH 1/2] Add mypy for testing


Add type hints and static analysis.

---

diff --git a/.gitignore b/.gitignore
index 4904909..4ad110f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,7 @@
 tests/test_freshmaker.db
 freshmaker.db
 .pytest_cache
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
diff --git a/tox.ini b/tox.ini
index 8a43a06..2e7f8da 100644
--- a/tox.ini
+++ b/tox.ini
@@ -4,7 +4,7 @@
 # and then run "tox" from this directory.
 
 [tox]
-envlist = py37, flake8, bandit
+envlist = py37, flake8, bandit, mypy
 
 [testenv]
 basepython = python3
@@ -27,6 +27,13 @@ skip_install = true
 deps = flake8
 commands = flake8
 
+[testenv:mypy]
+description = type check
+deps =
+    mypy
+commands =
+        mypy --ignore-missing-imports freshmaker
+
 [testenv:bandit]
 basepython = python3
 skip_install = true

From ef6262e83a7f4112a0c894244579fa1defd36bcb Mon Sep 17 00:00:00 2001
From: Mariana Ulaieva <mulaieva@redhat.com>
Date: Apr 29 2020 14:36:34 +0000
Subject: [PATCH 2/2] Fix type issues


Fix issues detected by mypy.

---

diff --git a/conf/config.py b/conf/config.py
index c6002bd..c7aa80c 100644
--- a/conf/config.py
+++ b/conf/config.py
@@ -2,6 +2,7 @@
 
 import os
 import tempfile
+from typing import Optional, Tuple, Union
 
 from freshmaker.config import all_, any_  # noqa
 
@@ -148,9 +149,9 @@ class BaseConfiguration(object):
     # Path to credential cache file. This optional could be None when not using
     # a client keytab to acquire credential.
     KRB_AUTH_CCACHE_FILE = tempfile.mkstemp(
-        suffix=str(os.getpid()), prefix="freshmaker_cc_")
+        suffix=str(os.getpid()), prefix="freshmaker_cc_")  # type: Union[Tuple[int, str], Optional[str]]
 
-    # Select which authentication backend to work with. There are 3 choices
+    # Select which authentication backend to work with. There are 3 choices Tuple[int, str]
     # noauth: no authentication is enabled. Useful for development particularly.
     # kerberos: Kerberos authentication is enabled.
     # openidc: OpenIDC authentication is enabled.
diff --git a/freshmaker/__init__.py b/freshmaker/__init__.py
index bde7790..a60fdcd 100644
--- a/freshmaker/__init__.py
+++ b/freshmaker/__init__.py
@@ -26,6 +26,7 @@
 import pkg_resources
 
 from logging import getLogger
+from typing import Any
 
 from flask import Flask
 from flask_login import LoginManager
@@ -40,12 +41,12 @@ try:
 except pkg_resources.DistributionNotFound:
     version = 'unknown'
 
-app = Flask(__name__)
+app = Flask(__name__)  # type: Any
 app.wsgi_app = ReverseProxy(app.wsgi_app)
 
 conf = init_config(app)
 
-db = SQLAlchemy(app)
+db = SQLAlchemy(app)  # type: Any
 
 init_logging(conf)
 log = getLogger(__name__)
diff --git a/freshmaker/config.py b/freshmaker/config.py
index 4be92c5..79e936e 100644
--- a/freshmaker/config.py
+++ b/freshmaker/config.py
@@ -29,7 +29,7 @@ import imp
 import os
 import threading
 
-from os import sys
+from os import sys  # type: ignore
 from freshmaker import logger
 
 
diff --git a/freshmaker/events.py b/freshmaker/events.py
index c776b8a..677c2d0 100644
--- a/freshmaker/events.py
+++ b/freshmaker/events.py
@@ -22,6 +22,7 @@
 # Written by Jan Kaluza <jkaluza@redhat.com>
 
 import itertools
+from typing import Dict, Any
 
 from freshmaker import conf
 from freshmaker.types import ArtifactType
@@ -31,7 +32,7 @@ from inspect import signature
 
 class BaseEvent(object):
 
-    _parsers = {}
+    _parsers = {}  # type: Dict[Any, Any]
 
     def __init__(self, msg_id, manual=False, dry_run=False):
         """
diff --git a/freshmaker/parsers/__init__.py b/freshmaker/parsers/__init__.py
index 2cd7b00..578e669 100644
--- a/freshmaker/parsers/__init__.py
+++ b/freshmaker/parsers/__init__.py
@@ -22,6 +22,7 @@
 # Written by Jan Kaluza <jkaluza@redhat.com>
 
 import abc
+from typing import List
 
 
 class BaseParser(object):
@@ -30,7 +31,7 @@ class BaseParser(object):
     """
     __metaclass__ = abc.ABCMeta
     name = "abstract_parser"
-    topic_suffixes = []
+    topic_suffixes = []  # type: List[str]
 
     @abc.abstractmethod
     def can_parse(self, topic, msg):
diff --git a/test-requirements.txt b/test-requirements.txt
index e3443ff..dafa4e3 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -5,6 +5,7 @@ pytest
 pytest-cov
 vcrpy
 tox
+mypy
 # It seems like Flask needs this itsdangerous package.
 # But there's a bug in a previous version:
 # https://github.com/pallets/itsdangerous/issues/102
diff --git a/tox.ini b/tox.ini
index 2e7f8da..dc1c3ed 100644
--- a/tox.ini
+++ b/tox.ini
@@ -32,7 +32,7 @@ description = type check
 deps =
     mypy
 commands =
-        mypy --ignore-missing-imports freshmaker
+        mypy --ignore-missing-imports .
 
 [testenv:bandit]
 basepython = python3

