Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/setup-python@v1
with:
# matches compat target in setup.py
python-version: '3.6'
python-version: '3.8'
- name: "Main Script"
run: |
curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-flake8.sh
Expand All @@ -35,6 +35,19 @@ jobs:
curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-pylint.sh
. ./prepare-and-run-pylint.sh "$(basename $GITHUB_REPOSITORY)" examples/*.py test/test_*.py experiments/*.py

mypy:
name: Mypy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Main Script"
run: |
curl -L -O https://tiker.net/ci-support-v0
. ./ci-support-v0
build_py_project_in_conda_env
python -m pip install mypy
./run-mypy.sh

pytest3:
name: Pytest Conda Py3
runs-on: ubuntu-latest
Expand Down
12 changes: 12 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ Pylint:
except:
- tags

Mypy:
script: |
curl -L -O https://tiker.net/ci-support-v0
. ./ci-support-v0
build_py_project_in_venv
python -m pip install mypy
./run-mypy.sh
tags:
- python3
except:
- tags

Downstream:
parallel:
matrix:
Expand Down
11 changes: 6 additions & 5 deletions meshmode/mesh/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def _filter_mesh_groups(mesh, selected_elements, vertex_id_dtype):
filtered_vertex_indices = [
mesh.groups[i_old_grp].vertex_indices[
filtered_group_elements[i_new_grp], :]
for i_new_grp, i_old_grp in enumerate(new_group_to_old_group)]
for i_new_grp, i_old_grp in enumerate(new_group_to_old_group)
if mesh.groups[i_old_grp].vertex_indices is not None]

if n_new_groups > 0:
filtered_vertex_indices_flat = np.concatenate([indices.ravel() for indices
Expand Down Expand Up @@ -1287,14 +1288,14 @@ def map_mesh(mesh, f): # noqa
# {{{ affine map

def affine_map(mesh,
A: Optional[Union[Real, np.ndarray]] = None, # noqa: N803
b: Optional[Union[Real, np.ndarray]] = None):
A: Optional[Union[np.generic, np.ndarray]] = None, # noqa: N803
b: Optional[Union[np.generic, np.ndarray]] = None):
"""Apply the affine map :math:`f(x) = A x + b` to the geometry of *mesh*."""

if isinstance(A, Real):
if A is not None and not isinstance(A, np.ndarray):
A = np.diag([A] * mesh.ambient_dim) # noqa: N806

if isinstance(b, Real):
if b is not None and not isinstance(b, np.ndarray):
Comment on lines -1290 to +1298
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@inducer I had a little trouble here: the type checking for the numpy functions doesn't like Real. I get this error with the original code:

meshmode/mesh/processing.py:1295: error: Argument 1 to "diag" has incompatible type "List[Real]"; expected "Union[_SupportsArray[dtype[Any]], Sequence[_SupportsArray[dtype[Any]]], Sequence[Sequence[_SupportsArray[dtype[Any]]]], Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]], Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]]]]"  [arg-type]

The change fixes it, but I'm not sure if there's something more specific I can use instead of np.generic (or if this can be written in a different way to avoid the issue).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is OK for now. Mypy is still at war with Python's numerical tower, cf. python/mypy#3186 for example. I expect that this will get better with time.

b = np.array([b] * mesh.ambient_dim)

if A is None and b is None:
Expand Down
3 changes: 3 additions & 0 deletions run-mypy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python -m mypy --show-error-codes meshmode # examples test
65 changes: 65 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,68 @@ docstring-quotes = """
multiline-quotes = """

# enable-flake8-bugbear

[mypy]
python_version = 3.8
warn_unused_ignores = True

exclude = (?x)(
meshmode/discretization/.*
| meshmode/mesh/__init__.py
| meshmode/mesh/generation\.py
| meshmode/mesh/visualization\.py
| meshmode/mesh/refinement/.*
| meshmode/interop/.*
| meshmode/dof_array\.py
)

[mypy-pyvisfile.*]
ignore_missing_imports = True

[mypy-matplotlib.*]
ignore_missing_imports = True

[mypy-mpl_toolkits.*]
ignore_missing_imports = True

[mypy-firedrake.*]
ignore_missing_imports = True

[mypy-pyop2.*]
ignore_missing_imports = True

[mypy-finat.*]
ignore_missing_imports = True

[mypy-FIAT.*]
ignore_missing_imports = True

[mypy-loopy.*]
ignore_missing_imports = True

[mypy-gmsh_interop.*]
ignore_missing_imports = True

[mypy-scipy.*]
ignore_missing_imports = True

[mypy-pymetis.*]
ignore_missing_imports = True

[mypy-pymbolic.*]
ignore_missing_imports = True

[mypy-recursivenodes.*]
ignore_missing_imports = True

[mypy-mayavi.*]
ignore_missing_imports = True

[mypy-h5py.*]
ignore_missing_imports = True

[mypy-oct2py.*]
ignore_missing_imports = True

[mypy-pyopencl.*]
ignore_missing_imports = True
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ def main():
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Information Analysis",
"Topic :: Scientific/Engineering :: Mathematics",
Expand All @@ -39,7 +36,7 @@ def main():
],

packages=find_packages(),
python_requires="~=3.6",
python_requires="~=3.8",
install_requires=[
"numpy",
"modepy>=2020.2",
Expand Down