diff --git a/.circleci/config.yml b/.circleci/config.yml index 6c33d64..131410f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,6 +23,17 @@ jobs: sudo pip install nox nox -f noxfile.py -s lint + Type Check: + - image: circleci/python:3.7.1 + + steps: + - checkout + - run: + command: | + sudo pip install virtualenv + sudo pip install nox + nox -f noxfile.py -s type_check + Release: docker: - image: circleci/python:3.7.1 @@ -43,6 +54,7 @@ workflows: jobs: - Unit Test - Lint + - Type Check release: jobs: - Release: diff --git a/.gitignore b/.gitignore index c4f832a..19baadd 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ coverage.xml *.cover .hypothesis/ .pytest_cache/ +.pytype # Translations *.mo diff --git a/noxfile.py b/noxfile.py index 26668e8..52e4160 100644 --- a/noxfile.py +++ b/noxfile.py @@ -44,3 +44,14 @@ def unit(session, pip_installs): 'tests', *session.posargs ) + +@nox.session +def type_check(session): + """Run type checking using pytype.""" + session.install('-e', '.[dev]') + session.install('pytype') + session.run( + 'pytype', + '--python-version=3.6', + '--disable=pyi-error', + 'pybadges') diff --git a/pybadges/precalculated_text_measurer.py b/pybadges/precalculated_text_measurer.py index 7f0be9b..4ccd9fd 100644 --- a/pybadges/precalculated_text_measurer.py +++ b/pybadges/precalculated_text_measurer.py @@ -20,7 +20,7 @@ Uses a precalculated set of metrics to calculate the string length. import io import json import pkg_resources -from typing import Mapping, TextIO, Type +from typing import cast, Mapping, TextIO, Type from pybadges import text_measurer @@ -80,7 +80,8 @@ class PrecalculatedTextMeasurer(text_measurer.TextMeasurer): with pkg_resources.resource_stream(__name__, 'default-widths.json.xz') as f: with lzma.open(f, "rt") as g: - cls._default_cache = PrecalculatedTextMeasurer.from_json(g) + cls._default_cache = PrecalculatedTextMeasurer.from_json( + cast(TextIO, g)) return cls._default_cache elif pkg_resources.resource_exists(__name__, 'default-widths.json'): with pkg_resources.resource_stream(__name__,