From cd4cf2eebba87c2db4c608ad3db075656ba54f0e Mon Sep 17 00:00:00 2001 From: Chris Marchbanks Date: Wed, 1 Dec 2021 00:15:19 -0700 Subject: [PATCH] Add mypy linting to the CI pipeline Signed-off-by: Chris Marchbanks --- .circleci/config.yml | 7 +++++++ mypy.ini | 5 +++++ tests/test_core.py | 6 +----- tests/test_exposition.py | 7 +------ tests/test_graphite_bridge.py | 6 +----- tox.ini | 11 ++++++++++- 6 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 mypy.ini diff --git a/.circleci/config.yml b/.circleci/config.yml index ced00806..f3712da7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,6 +19,12 @@ jobs: - checkout - run: pip install tox - run: tox -e isort + mypy_lint: + executor: python + steps: + - checkout + - run: pip install tox + - run: tox -e mypy test: parameters: python: @@ -64,6 +70,7 @@ workflows: jobs: - flake8_lint - isort_lint + - mypy_lint - test: matrix: parameters: diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..c1b51f59 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,5 @@ +[mypy] +exclude = prometheus_client/decorator.py|prometheus_client/twisted|tests/test_twisted.py + +[mypy-prometheus_client.decorator] +follow_imports = skip diff --git a/tests/test_core.py b/tests/test_core.py index 38bc20c4..36d521cc 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,5 +1,6 @@ from concurrent.futures import ThreadPoolExecutor import time +import unittest import pytest @@ -11,11 +12,6 @@ ) from prometheus_client.decorator import getargspec -try: - import unittest2 as unittest -except ImportError: - import unittest - def assert_not_observable(fn, *args, **kwargs): """ diff --git a/tests/test_exposition.py b/tests/test_exposition.py index a52805ea..fd130552 100644 --- a/tests/test_exposition.py +++ b/tests/test_exposition.py @@ -1,3 +1,4 @@ +from http.server import BaseHTTPRequestHandler, HTTPServer import threading import time import unittest @@ -15,12 +16,6 @@ passthrough_redirect_handler, ) -try: - from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer -except ImportError: - # Python 3 - from http.server import BaseHTTPRequestHandler, HTTPServer - class TestGenerateText(unittest.TestCase): def setUp(self): diff --git a/tests/test_graphite_bridge.py b/tests/test_graphite_bridge.py index 73b38204..5e281486 100644 --- a/tests/test_graphite_bridge.py +++ b/tests/test_graphite_bridge.py @@ -1,14 +1,10 @@ +import socketserver as SocketServer import threading import unittest from prometheus_client import CollectorRegistry, Gauge from prometheus_client.bridge.graphite import GraphiteBridge -try: - import SocketServer -except ImportError: - import socketserver as SocketServer - def fake_timer(): return 1434898897.5 diff --git a/tox.ini b/tox.ini index 8a93a160..25a7a00a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = coverage-clean,py3.6,py3.7,py3.8,py3.9,py3.10,pypy3.7,py3.9-nooptionals,coverage-report,flake8,isort +envlist = coverage-clean,py3.6,py3.7,py3.8,py3.9,py3.10,pypy3.7,py3.9-nooptionals,coverage-report,flake8,isort,mypy [base] @@ -48,6 +48,15 @@ skip_install = true commands = isort --check prometheus_client/ tests/ setup.py +[testenv:mypy] +deps = + pytest + asgiref + mypy==0.910 +skip_install = true +commands = + mypy --install-types --non-interactive prometheus_client/ tests/ + [flake8] ignore = D,