Skip to content

Commit 4698624

Browse files
committed
Get mypy-clean, enable mypy in CI
Also, required from __future__ import annotations
1 parent 0f5fdad commit 4698624

40 files changed

+367
-129
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ jobs:
2525
- uses: actions/checkout@v4
2626
- uses: crate-ci/typos@master
2727

28+
mypy:
29+
name: Mypy
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
-
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.x'
37+
- name: "Main Script"
38+
run: |
39+
curl -L -O https://tiker.net/ci-support-v0
40+
. ./ci-support-v0
41+
build_py_project_in_conda_env
42+
python -m pip install mypy
43+
mypy $(get_proj_name)
44+
2845
pylint:
2946
name: Pylint
3047
runs-on: ubuntu-latest

.gitlab-ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ Pylint:
140140
except:
141141
- tags
142142

143+
Mypy:
144+
script: |
145+
curl -L -O https://tiker.net/ci-support-v0
146+
. ./ci-support-v0
147+
build_py_project_in_venv
148+
python -m pip install mypy
149+
mypy $(get_proj_name)
150+
tags:
151+
- python3
152+
except:
153+
- tags
154+
143155
Downstream:
144156
parallel:
145157
matrix:

benchmarks/bench_translations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24

35
import numpy as np

pyproject.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ extend-select = [
1616
"UP", # pyupgrade
1717
"RUF", # ruff
1818
"W", # pycodestyle
19+
20+
# TODO
21+
# "SIM",
1922
]
2023
extend-ignore = [
2124
"C90", # McCabe complexity
@@ -42,6 +45,12 @@ known-local-folder = [
4245
"sumpy",
4346
]
4447
lines-after-imports = 2
48+
required-imports = ["from __future__ import annotations"]
49+
50+
[tool.ruff.lint.per-file-ignores]
51+
"doc/**/*.py" = ["I002"]
52+
"examples/**/*.py" = ["I002"]
53+
"setup.py" = ["I002"]
4554

4655
[tool.typos.default]
4756
extend-ignore-re = [
@@ -61,3 +70,23 @@ extend-exclude = [
6170
"contrib/*/*.ipynb",
6271
"notes/*/*.eps",
6372
]
73+
74+
[tool.mypy]
75+
warn_unused_ignores = true
76+
77+
[[tool.mypy.overrides]]
78+
module = [
79+
"pyopencl.*",
80+
"pymbolic.*",
81+
"loopy.*",
82+
"symengine.*",
83+
"boxtree.*",
84+
"pyvkfft.*",
85+
"pyfmmlib.*",
86+
"mayavi.*",
87+
"scipy.*",
88+
"sympy.*",
89+
"matplotlib.*",
90+
"pyvisfile.*",
91+
]
92+
ignore_missing_imports = true

sumpy/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2013 Andreas Kloeckner"
25

36
__license__ = """
@@ -21,7 +24,9 @@
2124
"""
2225

2326
import os
27+
from typing import Hashable
2428

29+
import loopy as lp
2530
from pytools.persistent_dict import WriteOncePersistentDict
2631

2732
from sumpy.e2e import (
@@ -56,8 +61,8 @@
5661
]
5762

5863

59-
code_cache = WriteOncePersistentDict("sumpy-code-cache-v6-"+VERSION_TEXT,
60-
safe_sync=False)
64+
code_cache: WriteOncePersistentDict[Hashable, lp.TranslationUnit] = \
65+
WriteOncePersistentDict("sumpy-code-cache-v6-"+VERSION_TEXT, safe_sync=False)
6166

6267

6368
# {{{ optimization control

sumpy/array_context.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2022 Alexandru Fikl"
25

36
__license__ = """

sumpy/assignment_collection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2012 Andreas Kloeckner"
25

36
__license__ = """

sumpy/codegen.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = "Copyright (C) 2012 Andreas Kloeckner"
25

36
__license__ = """

sumpy/cse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = """
25
Copyright (C) 2017 Matt Wala
36
Copyright (C) 2006-2016 SymPy Development Team

sumpy/derivative_taker.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
__copyright__ = """
25
Copyright (C) 2012 Andreas Kloeckner
36
Copyright (C) 2020 Isuru Fernando
@@ -338,7 +341,7 @@ def diff(self, mi, q=0):
338341

339342
# {{{ DifferentiatedExprDerivativeTaker
340343

341-
DerivativeCoeffDict = Dict[Tuple[int], Any]
344+
DerivativeCoeffDict = Dict[Tuple[int, ...], Any]
342345

343346

344347
@tag_dataclass
@@ -390,7 +393,7 @@ def diff_derivative_coeff_dict(derivative_coeff_dict: DerivativeCoeffDict,
390393
and return a new derivative transformation dictionary.
391394
"""
392395
from collections import defaultdict
393-
new_derivative_coeff_dict = defaultdict(lambda: 0)
396+
new_derivative_coeff_dict: DerivativeCoeffDict = defaultdict(lambda: 0)
394397

395398
for mi, coeff in derivative_coeff_dict.items():
396399
# In the case where we have x * u.diff(x), the result should

0 commit comments

Comments
 (0)