Skip to content

Commit

Permalink
feat: add 'py.typed' declaration (#119)
Browse files Browse the repository at this point in the history
Check typing under CI using new 'mypy' nox session.
  • Loading branch information
tseaver authored Dec 22, 2021
1 parent b1a8d14 commit f1c91c2
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mypy]
python_version = 3.6
exclude = tests/unit/resources/
12 changes: 12 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
2 changes: 1 addition & 1 deletion src/google_crc32c/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions src/google_crc32c/cext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 2 additions & 0 deletions src/google_crc32c/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file for PEP 561.
# The google_crc32c package uses inline types.
2 changes: 1 addition & 1 deletion tests/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import itertools
from unittest import mock

import pytest
import pytest # type: ignore

import google_crc32c

Expand Down

0 comments on commit f1c91c2

Please sign in to comment.