Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mypy type checking #133

Closed
wants to merge 4 commits into from
Closed
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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@ repos:
rev: v2.2.4
hooks:
- id: codespell

dstansby marked this conversation as resolved.
Show resolved Hide resolved
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.1.1' # Use the sha / tag you want to point at
hooks:
- id: mypy
additional_dependencies: ['types-setuptools']
ci:
autofix_prs: false
2 changes: 2 additions & 0 deletions changelog/133.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``mypy`` type checking has been enabled on the repository.
Types have not yet been extensively added, but running ``mypy`` does not raise any errors.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
try:
get_distribution(requirement)
except Exception as e:
missing_requirements.append(requirement.name)
missing_requirements.append(requirement.project_name)
if missing_requirements:
print(
f"The {' '.join(missing_requirements)} package(s) could not be found and "
Expand Down
3 changes: 2 additions & 1 deletion sunkit_image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Documentation: https://sunkit-image.readthedocs.io/en/latest/
"""
import sys
from typing import List

from .version import version as __version__

Expand All @@ -25,4 +26,4 @@ class UnsupportedPythonError(Exception):
# This has to be .format to keep backwards compatibly.
raise UnsupportedPythonError("sunkit_image does not support Python < {}".format(__minimum_python_version__))

__all__ = []
__all__: List[str] = []
2 changes: 1 addition & 1 deletion sunkit_image/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import tempfile
import importlib
import importlib.util

import numpy as np
import pytest
Expand Down
10 changes: 0 additions & 10 deletions sunkit_image/tests/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,6 @@ def test_erase_loop_in_image(image, test_map):
assert np.allclose(expect, result)


@pytest.fixture
def test_image():
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
# An image containing a loop in a straight line
ima = np.zeros((3, 3), dtype=np.float32)
ima[0, 1] = 5
ima[1, 1] = 3
ima[2, 1] = 0
return ima


def test_initial_direction_finding(test_image):
# The starting point of the loop i.e. the maximumflux position
xstart = 0
Expand Down
6 changes: 4 additions & 2 deletions sunkit_image/time_lag.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Useful for understanding time variability in EUV light curves.
"""
from typing import Optional

import numpy as np

import astropy.units as u
Expand Down Expand Up @@ -162,7 +164,7 @@ def _dask_check(lags, indices):


@u.quantity_input
def time_lag(signal_a, signal_b, time: u.s, lag_bounds: (u.s, None) = None, **kwargs):
def time_lag(signal_a, signal_b, time: u.s, lag_bounds: Optional[u.Quantity[u.s]] = None, **kwargs):
r"""
Compute the time lag that maximizes the cross-correlation between
``signal_a`` and ``signal_b``.
Expand Down Expand Up @@ -236,7 +238,7 @@ def time_lag(signal_a, signal_b, time: u.s, lag_bounds: (u.s, None) = None, **kw


@u.quantity_input
def max_cross_correlation(signal_a, signal_b, time: u.s, lag_bounds: (u.s, None) = None):
def max_cross_correlation(signal_a, signal_b, time: u.s, lag_bounds: Optional[u.Quantity[u.s]] = None):
dstansby marked this conversation as resolved.
Show resolved Hide resolved
"""
Compute the maximum value of the cross-correlation between ``signal_a`` and
``signal_b``.
Expand Down
2 changes: 2 additions & 0 deletions sunkit_image/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# mypy: disable-error-code="no-redef"

# NOTE: First try _dev.scm_version if it exists and setuptools_scm is installed
# This file is not included in sunkit-image wheels/tarballs, so otherwise it will
# fall back on the generated _version module.
Expand Down