Skip to content

Commit 4bf984d

Browse files
authored
Add mypy config; run mypy in CI (#286)
1 parent f2b98c7 commit 4bf984d

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

.github/workflows/mypy.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: mypy
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
env:
13+
FORCE_COLOR: 1
14+
TERM: xterm-256color # needed for FORCE_COLOR to work on mypy on Ubuntu, see https://github.com/python/mypy/issues/13817
15+
16+
jobs:
17+
mypy:
18+
name: Check code with mypy
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: actions/setup-python@v4
23+
with:
24+
cache: "pip"
25+
cache-dependency-path: "pyproject.toml"
26+
python-version: "3.11"
27+
- run: pip install -e .[dev]
28+
- run: pip freeze --all
29+
- run: mypy

pyperformance/_benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def run(self, python, runid=None, pyperf_opts=None, *,
182182
python = venv.python
183183

184184
if not runid:
185-
from ..run import get_run_id
185+
from .run import get_run_id
186186
runid = get_run_id(python, self)
187187

188188
runscript = self.runscript

pyperformance/_pyproject_toml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import packaging.version
2121

2222
try:
23-
import tomllib
23+
import tomllib # type: ignore[import] # tomllib doesn't exist on 3.7-3.10
2424
except ImportError:
2525
import tomli as tomllib
2626

pyproject.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ dependencies = [
6868
[project.optional-dependencies]
6969
dev = [
7070
'tox',
71+
'mypy==1.2.0',
72+
'tomli', # Needed even on 3.11+ for typechecking with mypy
7173
]
7274

7375
[project.scripts]
@@ -81,3 +83,24 @@ find = {} # Scanning implicit namespaces is active by default
8183

8284
[tool.setuptools.dynamic]
8385
version = {attr = "pyperformance.__version__"}
86+
87+
[tool.mypy]
88+
python_version = "3.7"
89+
pretty = true
90+
enable_error_code = "ignore-without-code"
91+
disallow_any_generics = true
92+
strict_concatenate = true
93+
warn_redundant_casts = true
94+
warn_unused_ignores = true
95+
warn_unused_configs = true
96+
files = [
97+
'pyperformance/',
98+
]
99+
exclude = [
100+
'pyperformance/data-files/',
101+
'pyperformance/tests/'
102+
]
103+
104+
[[tool.mypy.overrides]]
105+
module = "pyperf"
106+
ignore_missing_imports = true

tox.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py3, pypy3, doc, pep8
2+
envlist = py3, pypy3, doc, pep8, mypy
33
isolated_build = True
44

55
[testenv]
@@ -27,3 +27,10 @@ commands = flake8 pyperformance runtests.py setup.py
2727
# E741 ambiguous variable name 'l' (don't modify benhcmarks just for that)
2828
# W503 line break before binary operator
2929
ignore = E501,E741,W503
30+
31+
[testenv:mypy]
32+
basepython = python3
33+
deps=
34+
mypy
35+
tomli
36+
commands = mypy

0 commit comments

Comments
 (0)