Skip to content

Commit da55457

Browse files
committed
Add infrastructure for type checking in Python code
Type annotations are provided in the project's Python code to indicate the types of objects. Previously no infrastructure was provided to leverage or validate these annotations. A task is added here to allow contributors to easily check for typing problems using the mypy tool. A new job is added to the "Check Python" GitHub Actions workflow to run the task on every push or pull request that modifies relevant files.
1 parent 19f5e91 commit da55457

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed

.github/workflows/check-python-task.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ on:
1515
- "**/poetry.lock"
1616
- "**/pyproject.toml"
1717
- "**/setup.cfg"
18+
- ".mypy.ini"
19+
- "mypy.ini"
1820
- "Taskfile.ya?ml"
1921
- "**/tox.ini"
2022
- "**.py"
@@ -25,6 +27,8 @@ on:
2527
- "**/poetry.lock"
2628
- "**/pyproject.toml"
2729
- "**/setup.cfg"
30+
- ".mypy.ini"
31+
- "mypy.ini"
2832
- "Taskfile.ya?ml"
2933
- "**/tox.ini"
3034
- "**.py"
@@ -120,3 +124,34 @@ jobs:
120124

121125
- name: Check formatting
122126
run: git diff --color --exit-code
127+
128+
types:
129+
needs: run-determination
130+
if: needs.run-determination.outputs.result == 'true'
131+
runs-on: ubuntu-latest
132+
permissions:
133+
contents: read
134+
135+
steps:
136+
- name: Checkout repository
137+
uses: actions/checkout@v4
138+
139+
- name: Install Python
140+
uses: actions/setup-python@v5
141+
with:
142+
python-version: ${{ env.PYTHON_VERSION }}
143+
144+
- name: Install Poetry
145+
run: pip install poetry
146+
147+
- name: Install Task
148+
uses: arduino/setup-task@v1
149+
with:
150+
repo-token: ${{ secrets.GITHUB_TOKEN }}
151+
version: 3.x
152+
153+
- name: Check types
154+
uses: liskin/gh-problem-matcher-wrap@v3
155+
with:
156+
linters: mypy
157+
run: task python:check-types

Taskfile.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tasks:
1616
- task: markdown:lint
1717
- task: npm:validate
1818
- task: poetry:validate
19+
- task: python:check-types
1920
- task: python:lint
2021
- task: python:test
2122

@@ -233,6 +234,16 @@ tasks:
233234
poetry run \
234235
coverage report
235236
237+
python:check-types:
238+
desc: Check types in Python files
239+
deps:
240+
- task: poetry:install-deps
241+
cmds:
242+
- |
243+
poetry run \
244+
mypy \
245+
.
246+
236247
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python-task/Taskfile.yml
237248
python:format:
238249
desc: Format Python files

poetry.lock

Lines changed: 58 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ flake8 = "6.1.0"
1818
pep8-naming = "0.13.3"
1919
pytest = "7.4.3"
2020
pytest-mock = "3.12.0"
21+
mypy = "1.7.1"
2122

2223
[build-system]
2324
requires = ["poetry-core"]

0 commit comments

Comments
 (0)