Skip to content

Commit e70a3cf

Browse files
committed
More mypy cleanup.
1 parent 438a028 commit e70a3cf

File tree

7 files changed

+20
-18
lines changed

7 files changed

+20
-18
lines changed

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", "call-overload", "call-arg", "var-annotated"] #, "operator", "arg-type", "index", "call-arg", "return-value", "assignment", "attr-defined"]
305-
exclude = ['src/pymatgen/analysis', 'src/pymatgen/phonon', 'src/pymatgen/io/lobster', 'src/pymatgen/io/cp2k', 'src/pymatgen/io/aims', 'src/pymatgen/io/lammps', 'src/pymatgen/io/feff', 'src/pymatgen/io/abinit']
305+
exclude = ['src/pymatgen/analysis', 'src/pymatgen/phonon', 'src/pymatgen/io/lobster', 'src/pymatgen/io/cp2k', 'src/pymatgen/io/aims', 'src/pymatgen/io/lammps']
306306
plugins = ["numpy.typing.mypy_plugin"]
307307

308308
[[tool.mypy.overrides]]

src/pymatgen/core/units.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from collections.abc import Iterator
2525
from typing import Any
2626

27-
from numpy.typing import NDArray
27+
from numpy.typing import ArrayLike
2828
from typing_extensions import Self
2929

3030
__author__ = "Shyue Ping Ong, Matteo Giantomassi"
@@ -511,7 +511,7 @@ class ArrayWithUnit(np.ndarray):
511511

512512
def __new__(
513513
cls,
514-
input_array: NDArray,
514+
input_array: ArrayLike,
515515
unit: str | Unit,
516516
unit_type: str | None = None,
517517
) -> Self:

src/pymatgen/io/abinit/abiobjects.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from typing_extensions import Self
2222

23+
from pymatgen.core.periodic_table import DummySpecies, Element
2324
from pymatgen.core.structure import IStructure
2425

2526

@@ -164,7 +165,7 @@ def structure_from_abivars(cls=None, *args, **kwargs) -> Structure:
164165
)
165166

166167

167-
def species_by_znucl(structure: Structure) -> list[Species]:
168+
def species_by_znucl(structure: IStructure | Structure) -> list[Species | Element | DummySpecies]:
168169
"""Get list of unique specie found in structure **ordered according to sites**.
169170
170171
Example:
@@ -235,7 +236,7 @@ def structure_to_abivars(
235236
types_of_specie = species_by_znucl(structure)
236237

237238
znucl_type = [specie.number for specie in types_of_specie]
238-
typat = np.zeros(n_atoms, int)
239+
typat = np.zeros(n_atoms, int) # type:ignore[assignment]
239240
for atm_idx, site in enumerate(structure):
240241
typat[atm_idx] = types_of_specie.index(site.specie) + 1
241242

@@ -245,8 +246,8 @@ def structure_to_abivars(
245246

246247
# Set small values to zero. This usually happens when the CIF file
247248
# does not give structure parameters with enough digits.
248-
r_prim = np.where(np.abs(r_prim) > 1e-8, r_prim, 0.0)
249-
x_red = np.where(np.abs(x_red) > 1e-8, x_red, 0.0)
249+
r_prim = np.where(np.abs(r_prim) > 1e-8, r_prim, 0.0) # type:ignore[assignment]
250+
x_red = np.where(np.abs(x_red) > 1e-8, x_red, 0.0) # type:ignore[assignment]
250251

251252
# Info on atoms.
252253
dct = {

src/pymatgen/io/abinit/inputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ def __init__(
753753
pseudo_dir = os.path.abspath(pseudo_dir)
754754
if not os.path.isdir(pseudo_dir):
755755
raise self.Error(f"Directory {pseudo_dir} does not exist")
756-
pseudos = [os.path.join(pseudo_dir, p) for p in pseudos]
756+
pseudos = [os.path.join(pseudo_dir, p) for p in pseudos] # type:ignore[arg-type]
757757

758758
try:
759759
self._pseudos = PseudoTable.as_table(pseudos).get_pseudos_for_structure(self.structure)

src/pymatgen/io/abinit/pseudos.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ class Pseudo(MSONable, abc.ABC):
9292
"""
9393

9494
@classmethod
95-
def as_pseudo(cls, obj: Self | str) -> Self:
95+
def as_pseudo(cls, obj: Pseudo | str) -> Pseudo:
9696
"""Convert obj into a Pseudo.
9797
9898
Args:
9999
obj (str | Pseudo): Path to the pseudo file or a Pseudo object.
100100
"""
101-
return obj if isinstance(obj, cls) else cls.from_file(obj)
101+
return obj if isinstance(obj, cls) else cls.from_file(obj) # type:ignore[arg-type]
102102

103103
@classmethod
104104
def from_file(cls, filename: str) -> Self:
@@ -1558,9 +1558,9 @@ def from_dir(cls, top, exts=None, exclude_dirs="_*") -> Self | None:
15581558
if exts is None:
15591559
exts = ("psp8",)
15601560

1561-
for pseudo in find_exts(top, exts, exclude_dirs=exclude_dirs):
1561+
for pseudo in find_exts(top, exts, exclude_dirs=exclude_dirs): # type:ignore[assignment]
15621562
try:
1563-
pseudos.append(Pseudo.from_file(pseudo))
1563+
pseudos.append(Pseudo.from_file(pseudo)) # type:ignore[arg-type]
15641564
except Exception as exc:
15651565
logger.critical(f"Error in {pseudo}:\n{exc}")
15661566

src/pymatgen/io/feff/inputs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ def __init__(
188188
# if Structure, check symmetry
189189
if isinstance(self.struct, Structure):
190190
self.periodic = True
191-
sym = SpacegroupAnalyzer(struct, **self.spacegroup_analyzer_settings)
191+
sym = SpacegroupAnalyzer(struct, **self.spacegroup_analyzer_settings) # type:ignore[arg-type]
192192
data = sym.get_symmetry_dataset()
193193
self.space_number = data.number
194194
self.space_group = data.international
195195
# for Molecule, skip the symmetry check
196196
elif isinstance(self.struct, Molecule):
197197
self.periodic = False
198-
self.space_number = self.space_group = None
198+
self.space_number = self.space_group = None # type:ignore[assignment]
199199
else:
200200
raise TypeError("'struct' argument must be a Structure or Molecule!")
201201
self.comment = comment or "None given"
@@ -247,7 +247,7 @@ def header_string_from_file(filename: str = "feff.inp"):
247247
Reads header string.
248248
"""
249249
with zopen(filename, mode="rt", encoding="utf-8") as file:
250-
lines = file.readlines()
250+
lines: list[str] = file.readlines() # type:ignore[assignment]
251251
feff_header_str = []
252252
ln = 0
253253

@@ -669,7 +669,7 @@ def from_file(cls, filename: str = "feff.inp") -> Self:
669669
Tags
670670
"""
671671
with zopen(filename, mode="rt", encoding="utf-8") as file:
672-
lines = list(clean_lines(file.readlines()))
672+
lines: list[str] = list(clean_lines(file.readlines())) # type:ignore[arg-type]
673673
params = {}
674674
eels_params = []
675675
ieels = -1

src/pymatgen/io/feff/outputs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def from_file(cls, feff_inp_file: str = "feff.inp", ldos_file: str = "ldos") ->
7171
begin = 0
7272

7373
with zopen(pot_inp, mode="rt", encoding="utf-8") as potfile:
74-
for line in potfile:
74+
line: str
75+
for line in potfile: # type:ignore[assignment]
7576
if len(pot_read_end.findall(line)) > 0:
7677
break
7778

@@ -144,7 +145,7 @@ def from_file(cls, feff_inp_file: str = "feff.inp", ldos_file: str = "ldos") ->
144145
_t_dos: dict = {Spin.up: t_dos}
145146

146147
dos = Dos(e_fermi, dos_energies, _t_dos)
147-
complete_dos = CompleteDos(structure, dos, pdoss)
148+
complete_dos = CompleteDos(structure, dos, pdoss) # type:ignore[arg-type]
148149
charge_transfer = LDos.charge_transfer_from_file(feff_inp_file, ldos_file)
149150
return cls(complete_dos, charge_transfer)
150151

0 commit comments

Comments
 (0)