Add type validate

This commit is contained in:
Brian Quinlan
2019-04-09 10:43:13 -07:00
parent 2417eb007b
commit 16bd4361d2
4 changed files with 27 additions and 2 deletions

View File

@@ -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:

1
.gitignore vendored
View File

@@ -47,6 +47,7 @@ coverage.xml
*.cover
.hypothesis/
.pytest_cache/
.pytype
# Translations
*.mo

View File

@@ -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')

View File

@@ -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__,