Skip to content

Commit

Permalink
Merge pull request #1346 from effigies/fix/minmax-types
Browse files Browse the repository at this point in the history
TYP: Address some recent numpy/mypy type complaints
  • Loading branch information
effigies authored Sep 7, 2024
2 parents f3c2168 + e2fe190 commit 83eaf0b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 8 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: ".*/data/.*"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -13,15 +13,18 @@ repos:
- id: check-merge-conflict
- id: check-vcs-permalinks
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
rev: v0.6.4
hooks:
- id: ruff
args: [--fix, --show-fixes, --exit-non-zero-on-fix]
args: [ --fix ]
exclude: = ["doc", "tools"]
- id: ruff-format
exclude: = ["doc", "tools"]
- id: ruff
args: [ --select, ISC001, --fix ]
exclude: = ["doc", "tools"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.11.2
hooks:
- id: mypy
# Sync with project.optional-dependencies.typing
Expand All @@ -36,7 +39,7 @@ repos:
args: ["nibabel"]
pass_filenames: false
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies:
Expand Down
6 changes: 5 additions & 1 deletion nibabel/pointset.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ def dim(self) -> int:
"""The dimensionality of the space the coordinates are in"""
return self.coordinates.shape[1] - self.homogeneous

def __rmatmul__(self, affine: np.ndarray) -> Self:
# Use __rmatmul__ to prefer to compose affines. Mypy does not like that
# this conflicts with ndarray.__matmul__. We will need some more feedback
# on how this plays out for type-checking or code suggestions before we
# can do better than ignore.
def __rmatmul__(self, affine: np.ndarray) -> Self: # type: ignore[misc]
"""Apply an affine transformation to the pointset
This will return a new pointset with an updated affine matrix only.
Expand Down
2 changes: 1 addition & 1 deletion nibabel/volumeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def array_to_file(
# pre scale thresholds
mn, mx = _dt_min_max(in_dtype, mn, mx)
mn_out, mx_out = _dt_min_max(out_dtype)
pre_clips = max(mn, mn_out), min(mx, mx_out)
pre_clips = max(mn, mn_out), min(mx, mx_out) # type: ignore[type-var]
return _write_data(data, fileobj, out_dtype, order, pre_clips=pre_clips)
# In any case, we do not want to check for nans because we've already
# disallowed scaling that generates nans
Expand Down

0 comments on commit 83eaf0b

Please sign in to comment.