Skip to content

Commit 294134b

Browse files
committed
Update type checking.
1 parent c45053d commit 294134b

20 files changed

+74
-61
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
uv run ruff format --check .
3232
3333
- name: mypy
34-
run: uv run mypy -p pymatgen.core
34+
run: uv run mypy -p pymatgen.core -p pymatgen.symmetry -p pymatgen.util
3535

3636
- name: pyright
3737
run: uv run pyright src

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ ignore_missing_imports = true
302302
namespace_packages = true
303303
no_implicit_optional = false
304304
disable_error_code = ["annotation-unchecked", "override", "operator", "attr-defined", "union-attr", "misc"] #, "operator", "arg-type", "index", "call-arg", "return-value", "assignment", "attr-defined"]
305-
exclude = ['src/pymatgen/analysis', 'src/pymatgen/io', 'src/pymatgen/cli', 'src/pymatgen/electronic_structure', 'src/pymatgen/phonon']
305+
exclude = ['src/pymatgen/analysis', 'src/pymatgen/io', 'src/pymatgen/cli', 'src/pymatgen/electronic_structure', 'src/pymatgen/phonon', 'src/pymatgen/apps', 'src/pymatgen/vis', "src/pymatgen/alchemy"]
306306
plugins = ["numpy.typing.mypy_plugin"]
307307

308308
[[tool.mypy.overrides]]

src/pymatgen/command_line/bader_caller.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from monty.shutil import decompress_file
2929
from monty.tempfile import ScratchDir
3030

31+
from pymatgen.core import Structure
3132
from pymatgen.io.common import VolumetricData
3233
from pymatgen.io.vasp.inputs import Potcar
3334
from pymatgen.io.vasp.outputs import Chgcar
@@ -37,7 +38,7 @@
3738

3839
from typing_extensions import Self
3940

40-
from pymatgen.core import IStructure, Structure
41+
from pymatgen.core import IStructure
4142

4243
__author__ = "shyuepingong"
4344
__version__ = "0.1"
@@ -375,7 +376,7 @@ def get_oxidation_state_decorated_structure(self, nelects: list[int] | None = No
375376
Returns:
376377
Structure: with bader-analysis-based oxidation states.
377378
"""
378-
struct = self.structure.copy()
379+
struct = Structure.from_sites(self.structure)
379380
charges = [self.get_partial_charge(idx, None if not nelects else nelects[idx]) for idx in range(len(struct))]
380381
struct.add_oxidation_state_by_site(charges)
381382
return struct
@@ -407,12 +408,12 @@ def get_decorated_structure(self, property_name: str, average: bool = False) ->
407408
structure with site properties assigned via Bader Analysis
408409
"""
409410
vals = np.array([self.get_charge(i) for i in range(len(self.structure))])
410-
struct = self.structure.copy()
411+
struct = Structure.from_sites(self.structure)
411412
if average:
412413
vals = np.divide(vals, [d["atomic_vol"] for d in self.data])
413414
struct.add_site_property(property_name, vals)
414415
if property_name == "spin":
415-
struct.add_spin_by_site(vals)
416+
struct.add_spin_by_site(list(vals))
416417
return struct
417418

418419
@property

src/pymatgen/command_line/chargemol_caller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
from pathlib import Path
6262
from typing import Literal
6363

64-
from pymatgen.core import Structure
64+
from pymatgen.core import IStructure, Structure
6565

6666
__author__ = "Martin Siron, Andrew S. Rosen"
6767
__version__ = "0.1"
@@ -121,7 +121,7 @@ def __init__(
121121

122122
if self._chgcar_path:
123123
self.chgcar: Chgcar | None = Chgcar.from_file(self._chgcar_path)
124-
self.structure: Structure | None = self.chgcar.structure
124+
self.structure: Structure | IStructure | None = self.chgcar.structure
125125
self.natoms: list[int] | None = self.chgcar.poscar.natoms
126126

127127
else:

src/pymatgen/command_line/critic2_caller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Critic2Caller:
8181
"""Call critic2 and store standard output for further processing."""
8282

8383
@requires(
84-
which("critic2"),
84+
which("critic2"), # type: ignore[arg-type]
8585
"Critic2Caller requires the executable critic to be in the path. "
8686
"Please follow the instructions at https://github.com/aoterodelaroza/critic2.",
8787
)

src/pymatgen/command_line/enumlib_caller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959

6060
@requires(
61-
ENUM_CMD and MAKESTR_CMD,
61+
ENUM_CMD and MAKESTR_CMD, # type: ignore[arg-type]
6262
"EnumlibAdaptor requires the executables 'enum.x' or 'multienum.x' "
6363
"and 'makestr.x' or 'makeStr.py' to be in the path. Please download the "
6464
"library at https://github.com/msg-byu/enumlib and follow the instructions "
@@ -120,7 +120,7 @@ def __init__(
120120
finder = SpacegroupAnalyzer(structure, symm_prec)
121121
self.structure = finder.get_refined_structure()
122122
else:
123-
self.structure = structure
123+
self.structure = structure # type: ignore[assignment]
124124

125125
self.min_cell_size = min_cell_size
126126
self.max_cell_size = max_cell_size
@@ -372,7 +372,7 @@ def _get_structures(self, num_structs: int) -> list[Structure]:
372372
data = _file.read()
373373
data = re.sub(r"scale factor", "1", data)
374374
data = re.sub(r"(\d+)-(\d+)", r"\1 -\2", data)
375-
poscar = Poscar.from_str(data, self.index_species)
375+
poscar = Poscar.from_str(data, self.index_species) # type: ignore[arg-type]
376376
sub_structure = poscar.structure
377377
# Enumeration may have resulted in a super lattice. We need to
378378
# find the mapping from the new lattice to the old lattice, and

src/pymatgen/command_line/mcsqs_caller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Sqs(NamedTuple):
3131

3232

3333
@requires(
34-
which("mcsqs") and which("str2cif"),
34+
which("mcsqs") and which("str2cif"), # type: ignore[arg-type]
3535
"run_mcsqs requires first installing AT-AT, see https://www.brown.edu/Departments/Engineering/Labs/avdw/atat/",
3636
)
3737
def run_mcsqs(

src/pymatgen/command_line/vampire_caller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class VampireCaller:
5353
"""
5454

5555
@requires(
56-
VAMP_EXE,
56+
VAMP_EXE, # type: ignore[arg-type]
5757
"VampireCaller requires vampire-serial to be in the path."
5858
"Please follow the instructions at https://vampire.york.ac.uk/download/.",
5959
)

src/pymatgen/core/operations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def from_rotation_and_translation(
117117
affine_matrix[:3][:, 3] = translation_vec
118118
return cls(affine_matrix, tol)
119119

120-
def operate(self, point: NDArray[np.float64]) -> NDArray[np.float64]:
120+
def operate(self, point: ArrayLike) -> NDArray[np.float64]:
121121
"""Apply the operation on a point.
122122
123123
Args:
@@ -129,7 +129,7 @@ def operate(self, point: NDArray[np.float64]) -> NDArray[np.float64]:
129129
affine_point = np.asarray([*point, 1])
130130
return np.dot(self.affine_matrix, affine_point)[:3]
131131

132-
def operate_multi(self, points: NDArray[np.float64]) -> NDArray[np.float64]:
132+
def operate_multi(self, points: ArrayLike) -> NDArray[np.float64]:
133133
"""Apply the operation on a list of points.
134134
135135
Args:

src/pymatgen/core/structure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5063,7 +5063,7 @@ class Molecule(IMolecule, collections.abc.MutableSequence):
50635063

50645064
def __init__(
50655065
self,
5066-
species: Sequence[SpeciesLike],
5066+
species: Sequence[CompositionLike],
50675067
coords: Sequence[ArrayLike] | ArrayLike,
50685068
charge: float = 0.0,
50695069
spin_multiplicity: int | None = None,

0 commit comments

Comments
 (0)