Skip to content

Commit 6bd13af

Browse files
shyuepclaude
andcommitted
fix(lammps): narrow bond_expansion type for mypy
nn.Module's __getattr__ types attribute access as Tensor | Module; the else branch assigning ``be`` directly to ``self.bond_expansion: nn.Module`` tripped --strict mypy. Cast at the point of access (same pattern used for potential.data_mean elsewhere in this file). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 580255d commit 6bd13af

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/matgl/ext/_lammps.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ def __init__(self, model: nn.Module) -> None:
134134
# the kernel survives torch.jit.script.save. Gaussian / ExpNormal /
135135
# RadialBessel basis modules are already TorchScript-friendly and pass
136136
# through unchanged.
137-
be = model.bond_expansion
137+
# ``model.bond_expansion`` typed as ``Tensor | Module`` via nn.Module's
138+
# ``__getattr__``; the cast narrows it for mypy without runtime cost.
139+
from typing import cast
140+
141+
be = cast("nn.Module", model.bond_expansion)
138142
if getattr(be, "rbf_type", None) == "SphericalBessel":
139143
if not bool(be.rbf.smooth):
140144
raise NotImplementedError(

0 commit comments

Comments
 (0)