diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 1158c765..a9a0eb2f 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -7,6 +7,22 @@ on: jobs: + mypy: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.6" + - name: Install nox + run: | + python -m ensurepip + python -m pip install nox + - name: Run mypy + run: | + nox -s mypy + build-wheels-linux: name: ${{ matrix.os }} strategy: diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..19d08026 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.6 +exclude = tests/unit/resources/ diff --git a/noxfile.py b/noxfile.py index 2648c42c..1d247094 100644 --- a/noxfile.py +++ b/noxfile.py @@ -47,3 +47,15 @@ def check(session): # Run py.test against the unit tests. session.run("py.test", "tests") session.run("python", f"{HERE}/scripts/check_crc32c_extension.py", *session.posargs) + + +@nox.session(python="3.6") +def mypy(session): + """Verify type hints are mypy compatible.""" + session.install("-e", ".") + session.install( + "mypy", + "types-mock", + "types-setuptools", + ) + session.run("mypy", "src/google_crc32c/", "tests/") diff --git a/src/google_crc32c/__init__.py b/src/google_crc32c/__init__.py index 272b001e..cae23411 100644 --- a/src/google_crc32c/__init__.py +++ b/src/google_crc32c/__init__.py @@ -25,7 +25,7 @@ from google_crc32c import cext as impl implementation = "c" except ImportError as exc: - from google_crc32c import python as impl + from google_crc32c import python as impl # type: ignore warnings.warn(_SLOW_CRC32C_WARNING, RuntimeWarning) implementation = "python" diff --git a/src/google_crc32c/cext.py b/src/google_crc32c/cext.py index d7c452d6..4a764e38 100644 --- a/src/google_crc32c/cext.py +++ b/src/google_crc32c/cext.py @@ -16,9 +16,9 @@ # NOTE: ``__config__`` **must** be the first import because it (may) # modify the search path used to locate shared libraries. -import google_crc32c.__config__ -from google_crc32c._crc32c import extend -from google_crc32c._crc32c import value +import google_crc32c.__config__ # type: ignore +from google_crc32c._crc32c import extend # type: ignore +from google_crc32c._crc32c import value # type: ignore from google_crc32c._checksum import CommonChecksum diff --git a/src/google_crc32c/py.typed b/src/google_crc32c/py.typed new file mode 100644 index 00000000..076325e2 --- /dev/null +++ b/src/google_crc32c/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google_crc32c package uses inline types. diff --git a/tests/test___init__.py b/tests/test___init__.py index e7c44066..327713da 100644 --- a/tests/test___init__.py +++ b/tests/test___init__.py @@ -15,7 +15,7 @@ import itertools from unittest import mock -import pytest +import pytest # type: ignore import google_crc32c