Skip to content

Commit 6735c7e

Browse files
authored
Merge pull request #73 from mfisher87/add-typechecking
Add typechecking
2 parents bc6d63c + b9c78a0 commit 6735c7e

File tree

7 files changed

+43
-4
lines changed

7 files changed

+43
-4
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77

8-
unit-test-with-pytest:
8+
unit-test-and-typecheck:
99
runs-on: "ubuntu-latest"
1010
strategy:
1111
matrix:
@@ -46,3 +46,9 @@ jobs:
4646
# In Pythons >= 3.10, tests fail with `RuntimeError: Invalid DISPLAY
4747
# variable`, unless this variable is set:
4848
MPLBACKEND: "Agg"
49+
50+
- name: "Install mypy"
51+
run: "pip install mypy>=1.3"
52+
53+
- name: "Run typechecker"
54+
run: "make typecheck"

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ lint:
1010
pre-commit run --all-files --show-diff-on-failure --color always
1111

1212

13+
.PHONY: typecheck
14+
typecheck:
15+
mypy --version
16+
mypy viscm
17+
18+
1319
.PHONY: ci
14-
ci: lint test
20+
ci: lint typecheck test

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ python -m viscm --uniform-space buggy-CAM02-UCS -m Bezier edit /tmp/option_d.py
4343

4444
Note that there was a small bug in the assumed sRGB viewing conditions
4545
while designing viridis. It does not affect the outcome by much. Also
46-
see `python -m viscm --help`.
46+
see `python -m viscm --help`.

doc/contributing.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,12 @@ installed, GUI tests will be skipped. Install with:
6060
```bash
6161
sudo apt install xvfb
6262
```
63+
64+
65+
### Type check
66+
67+
```bash
68+
make typecheck
69+
```
70+
71+
Type checking requires `mypy`.

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies:
1111
- "scipy ~=1.10"
1212

1313
# Development
14+
- "mypy ~=1.3.0"
1415
- "pre-commit"
1516
- "pytest"
1617
- "pytest-cov"

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ packages = {find = {}}
4545
package-data = {viscm = ["examples/*"]}
4646

4747

48+
[tool.mypy]
49+
python_version = "3.8"
50+
51+
# These libraries don't have type stubs. Mypy will see them as `Any` and not
52+
# throw an [import] error.
53+
[[tool.mypy.overrides]]
54+
module = [
55+
"colorspacious",
56+
"matplotlib.*",
57+
"mpl_toolkits.*",
58+
"scipy.*",
59+
]
60+
ignore_missing_imports = true
61+
62+
63+
4864
[tool.black]
4965
target-version = ["py38", "py39", "py310", "py311"]
5066

viscm/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _make_window(
123123
cmap_uniform_space: str,
124124
save: Union[Path, None],
125125
quit_immediately: bool,
126-
):
126+
) -> Union[gui.ViewerWindow, gui.EditorWindow]:
127127
# Hold a reference so it doesn't get GC'ed
128128
fig = plt.figure()
129129
figure_canvas = gui.FigureCanvas(fig)
@@ -132,6 +132,7 @@ def _make_window(
132132
if cmap:
133133
cm.load(cmap)
134134

135+
v: Union[gui.viscm, gui.viscm_editor]
135136
# Easter egg! I keep typing 'show' instead of 'view' so accept both
136137
if action in ("view", "show"):
137138
if cm is None:

0 commit comments

Comments
 (0)