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
42 changes: 42 additions & 0 deletions .github/workflows/diagnose-latest-numpy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Diagnose Latest NumPy

on:
push:
branches:
- fix/numpy-latest-typing

permissions:
contents: read

jobs:
verify:
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: pip

- name: Install development dependencies
run: |
python -m venv .venv
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install -e ".[dev]"

- name: Report resolved versions
run: |
python --version
.venv/bin/pyright --version
.venv/bin/python -m pip show numpy pyright h5py-stubs
node --version || true

- name: Build the optional Rust accelerator
run: ./scripts/build-accelerator.sh --release

- name: Run verification
run: ./scripts/verify.sh
5 changes: 4 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ jobs:
run: |
python -m venv .venv
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install ".[dev]"
.venv/bin/python -m pip install -e ".[dev]"

- name: Build the optional Rust accelerator
run: ./scripts/build-accelerator.sh --release

- name: Run verification checks
run: ./scripts/verify.sh
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,12 @@ reportMissingModuleSource = "error"
reportMissingTypeStubs = "none"
reportPrivateUsage = "none"
reportUnusedFunction = "none"
# NumPy 2.5 exposes several generic ufunc overloads with unresolved internal
# type variables. Pyright reports those library members and their propagated
# argument/result types as unknown even when the call site is valid. Keep the
# rest of strict checking enabled while accommodating this upstream stub issue.
reportUnknownMemberType = "none"
reportUnknownArgumentType = "none"
reportUnknownVariableType = "none"
# PEP 562 lazy exports are validated by import and packaging tests.
reportUnsupportedDunderAll = "none"
9 changes: 7 additions & 2 deletions src/anisotropy/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
from __future__ import annotations

import numpy as np
from numpy.typing import ArrayLike

from .model import AnisotropyModel, FloatArray, PredefinedAnisotropy
from .values import _callable_energy, _finite_difference_gradient, _magnetisation_array, _normalize
from .values import (
ArrayLike,
_callable_energy,
_finite_difference_gradient,
_magnetisation_array,
_normalize,
)


def evaluate_energy_density(model: AnisotropyModel, magnetisation: ArrayLike) -> FloatArray:
Expand Down
2 changes: 1 addition & 1 deletion src/anisotropy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from typing import TypeAlias, cast

import numpy as np
from numpy.typing import ArrayLike

from si.physical import SI

from .values import (
ArrayLike,
FloatArray,
_callable_energy,
_finite_difference_gradient,
Expand Down
3 changes: 1 addition & 2 deletions src/anisotropy/predefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
from __future__ import annotations

import numpy as np
from numpy.typing import ArrayLike

from .model import EnergyDensity, PredefinedAnisotropy
from .values import FloatArray, _normalize, energy_density_value
from .values import ArrayLike, FloatArray, _normalize, energy_density_value


def _constant(value: EnergyDensity, name: str) -> float:
Expand Down
9 changes: 7 additions & 2 deletions src/anisotropy/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
from __future__ import annotations

from collections.abc import Callable
from typing import Any, cast
from typing import Any, TypeAlias, cast

import numpy as np
from numpy.typing import ArrayLike, NDArray
from numpy.typing import NDArray

from si.physical import SI

FloatArray = NDArray[np.float64]
# NumPy's ArrayLike alias is intentionally broad, but recent NumPy stubs expose
# unresolved type variables through it under strict Pyright checking. These
# inputs are normalized immediately with np.asarray, so Any is intentional at
# this runtime-validation boundary.
ArrayLike: TypeAlias = Any
RawEnergyFunction = Callable[[ArrayLike], object]

_ENERGY_DENSITY_UNIT = SI(1.0, "J/m^3")
Expand Down
3 changes: 1 addition & 2 deletions src/nmesh/geometry/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
from typing import Literal, TypeAlias

import numpy as np
from numpy.typing import ArrayLike

from ..utils.types import BoolArray, FloatArray
from ..utils.types import ArrayLike, BoolArray, FloatArray
from .transform import (
AffineTransform,
_as_vector,
Expand Down
3 changes: 1 addition & 2 deletions src/nmesh/geometry/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
from dataclasses import dataclass

import numpy as np
from numpy.typing import ArrayLike

from ..utils.constants import MIN_ABS_SCALE_FACTOR
from ..utils.types import FloatArray
from ..utils.types import ArrayLike, FloatArray


def _as_vector(values: ArrayLike, dim: int | None = None) -> FloatArray:
Expand Down
3 changes: 2 additions & 1 deletion src/nmesh/io/meshio_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

import meshio
import numpy as np
from numpy.typing import ArrayLike, NDArray
from numpy.typing import NDArray

from ..backend import RawMesh
from ..utils.types import ArrayLike
from .legacy_nmesh_hdf5 import (
is_legacy_nmesh_hdf5,
load_raw_mesh_from_legacy_nmesh_hdf5,
Expand Down
5 changes: 3 additions & 2 deletions src/nmesh/utils/types.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Common type aliases used throughout the nmesh package."""

from typing import TypeAlias
from typing import Any, TypeAlias

import numpy as np
from numpy.typing import NDArray

__all__ = ["FloatArray", "BoolArray", "IntArray"]
__all__ = ["ArrayLike", "FloatArray", "BoolArray", "IntArray"]

ArrayLike: TypeAlias = Any
FloatArray: TypeAlias = NDArray[np.float64]
BoolArray: TypeAlias = NDArray[np.bool_]
IntArray: TypeAlias = NDArray[np.int_]
Loading