Skip to content

Commit b11ee46

Browse files
authored
Add py.typed, run type checks as part of GitHub Actions (#31)
This PR: - adds the missing `py.typed` marker file that indicates to consumers that the code has usable type hints - moves type checks to the test job of `on-commit` GitHub Actions workflow, instead of the style job. (Those type checks are Python-version dependent, and we want our type hints to be valid for all supported Python versions.) - fixes type hints to be Python 3.8-compatible on the `fraction_to_float.py` script Note: we're hitting a (known, fixed in main) issue with mypy and Python 3.14, so we skip the type check on Python 3.14 for now. xref: python/mypy#19020
1 parent 4d40e8a commit b11ee46

File tree

6 files changed

+11
-3
lines changed

6 files changed

+11
-3
lines changed

.github/workflows/on-commit.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ jobs:
2323
allow-prereleases: true
2424
- name: Install dependencies
2525
run: python -m pip install -r requirements/test.txt
26+
- name: Check types with mypy
27+
run: python -m mypy .
28+
# Skip type check for Python 3.14, since it's hitting an argparse-related
29+
# issue in mypy: https://github.com/python/mypy/pull/19020
30+
if: matrix.python-version != '3.14'
2631
- name: Test with pytest
2732
run: python -m pytest
2833

@@ -44,4 +49,3 @@ jobs:
4449
python -m flake8 .
4550
python -m isort --check --diff .
4651
python -m black --check --diff .
47-
python -m mypy --strict .

proofs/fraction_to_float.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import typing
12
from math import gcd
23

34

4-
def find_cd(a: int, b: int) -> list[tuple[int, int]]:
5+
def find_cd(a: int, b: int) -> typing.List[typing.Tuple[int, int]]:
56
"""
67
Given a positive fraction a/b (expressed in lowest terms), find both
78
fractions c/d which are simpler than a/b and which satisfy |ad - bc| = 1.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ target-version = ['py38']
2727
profile = 'black'
2828
order_by_type = 'False'
2929

30+
[tool.mypy]
31+
strict = true
32+
3033
[tool.setuptools_scm]
3134
version_scheme = 'release-branch-semver'

requirements/style.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
black
22
flake8
33
isort
4-
mypy

requirements/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
mypy
12
pytest

src/simplefractions/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)