Skip to content

Commit 438a028

Browse files
committed
More mypy fixes.
1 parent 0490ab0 commit 438a028

File tree

8 files changed

+26
-26
lines changed

8 files changed

+26
-26
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/xr', 'src/pymatgen/io/pwmat', 'src/pymatgen/io/fiesta' , 'src/pymatgen/io/nwchem', 'src/pymatgen/io/phonopy', 'src/pymatgen/io/abinit', 'src/pymatgen/io/exciting']
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']
306306
plugins = ["numpy.typing.mypy_plugin"]
307307

308308
[[tool.mypy.overrides]]

src/pymatgen/io/exciting/inputs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ def __init__(
7272
raise ValueError("Structure with partial occupancies cannot be converted into exciting input!")
7373

7474
@property
75-
def lockxyz(self) -> NDArray:
75+
def lockxyz(self) -> NDArray | None:
7676
"""Selective dynamics site properties."""
77-
return self.structure.site_properties.get("selective_dynamics")
77+
return self.structure.site_properties.get("selective_dynamics") # type:ignore[return-value]
7878

7979
@lockxyz.setter
80-
def lockxyz(self, lockxyz: ArrayLike) -> NDArray:
81-
self.structure.add_site_property("selective_dynamics", lockxyz)
80+
def lockxyz(self, lockxyz: ArrayLike):
81+
self.structure.add_site_property("selective_dynamics", np.array(lockxyz))
8282

8383
@classmethod
8484
def from_str(cls, data: str) -> Self:
@@ -183,8 +183,8 @@ def from_file(cls, filename: PathLike) -> Self:
183183
ExcitingInput
184184
"""
185185
with zopen(filename, mode="rt", encoding="utf-8") as file:
186-
data = file.read().replace("\n", "")
187-
return cls.from_str(data)
186+
data = file.read().replace("\n", "") # type:ignore[arg-type]
187+
return cls.from_str(data) # type:ignore[arg-type]
188188

189189
def write_etree(
190190
self,

src/pymatgen/io/fiesta.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def write_file(self, filename: str | Path) -> None:
533533
filename: Filename.
534534
"""
535535
with zopen(filename, mode="wt", encoding="utf-8") as file:
536-
file.write(str(self))
536+
file.write(str(self)) # type:ignore[arg-type]
537537

538538
def as_dict(self):
539539
"""MSONable dict."""
@@ -565,7 +565,7 @@ def from_dict(cls, dct: dict) -> Self:
565565
)
566566

567567
@classmethod
568-
def from_str(cls, string_input: str) -> Self:
568+
def from_str(cls, string_input: str) -> FiestaInput:
569569
"""
570570
Read an FiestaInput from a string. Currently tested to work with
571571
files generated from this class itself.
@@ -700,7 +700,7 @@ def from_str(cls, string_input: str) -> Self:
700700
)
701701

702702
@classmethod
703-
def from_file(cls, filename: str | Path) -> Self:
703+
def from_file(cls, filename: str | Path) -> FiestaInput:
704704
"""
705705
Read an Fiesta input from a file. Currently tested to work with
706706
files generated from this class itself.
@@ -712,7 +712,7 @@ def from_file(cls, filename: str | Path) -> Self:
712712
FiestaInput object
713713
"""
714714
with zopen(filename, mode="rt", encoding="utf-8") as file:
715-
return cls.from_str(file.read())
715+
return cls.from_str(file.read()) # type:ignore[arg-type]
716716

717717

718718
class FiestaOutput:

src/pymatgen/io/nwchem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def from_file(cls, filename: str | Path) -> Self:
535535
NwInput object
536536
"""
537537
with zopen(filename, mode="rt", encoding="utf-8") as file:
538-
return cls.from_str(file.read())
538+
return cls.from_str(file.read()) # type:ignore[arg-type]
539539

540540

541541
class NwInputError(Exception):

src/pymatgen/io/phonopy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ def get_ph_bs_symm_line_from_dict(bands_dict, has_nac=False, labels_dict=None) -
163163
if eig_q:
164164
eigen_displacements.append(eig_q)
165165

166-
q_pts = np.array(q_pts)
166+
q_pts = np.array(q_pts) # type:ignore[assignment]
167167
# transpose to match the convention in PhononBandStructure
168-
frequencies = np.transpose(frequencies)
168+
frequencies = np.transpose(frequencies) # type:ignore[assignment]
169169
if eigen_displacements:
170-
eigen_displacements = np.transpose(eigen_displacements, (1, 0, 2, 3))
170+
eigen_displacements = np.transpose(eigen_displacements, (1, 0, 2, 3)) # type:ignore[assignment]
171171

172172
rec_lattice = Lattice(bands_dict["reciprocal_lattice"])
173173

@@ -338,7 +338,7 @@ def get_phonon_dos_from_fc(
338338
p_doses = dict(zip(structure, dos_raw[1], strict=True))
339339

340340
total_dos = PhononDos(dos_raw[0], dos_raw[1].sum(axis=0))
341-
return CompletePhononDos(structure, total_dos, p_doses)
341+
return CompletePhononDos(structure, total_dos, p_doses) # type:ignore[arg-type]
342342

343343

344344
@requires(Phonopy, "phonopy is required to calculate phonon band structures")
@@ -464,7 +464,7 @@ def get_gruneisenparameter(gruneisen_path, structure=None, structure_path=None)
464464
return GruneisenParameter(
465465
gruneisen=gruneisen_np,
466466
qpoints=q_pts_np,
467-
multiplicities=multiplicities_np,
467+
multiplicities=multiplicities_np, # type:ignore[arg-type]
468468
frequencies=frequencies_np,
469469
structure=structure,
470470
)

src/pymatgen/io/pwmat/inputs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,15 @@ def get_virial(self) -> np.ndarray | None:
360360
class AtomConfig(MSONable):
361361
"""Object for representing the data in a atom.config or final.config file."""
362362

363-
def __init__(self, structure: Structure | IStructure, sort_structure: bool = False):
363+
def __init__(self, structure: IStructure | Structure, sort_structure: bool = False):
364364
"""Initialization function.
365365
366366
Args:
367367
structure (Structure): Structure object
368368
sort_structure (bool, optional): Whether to sort the structure. Useful if species
369369
are not grouped properly together. Defaults to False.
370370
"""
371-
self.structure: Structure = structure
371+
self.structure: Structure = Structure.from_sites(structure)
372372
if sort_structure:
373373
self.structure = self.structure.get_sorted_structure()
374374
elements_counter = dict(sorted(Counter(self.structure.species).items()))
@@ -396,7 +396,7 @@ def from_str(cls, data: str, mag: bool = False) -> Self:
396396
properties: dict[str, float] = {}
397397
structure = Structure(
398398
lattice=ac_extractor.get_lattice(),
399-
species=ac_extractor.get_types(),
399+
species=ac_extractor.get_types(), # type:ignore[arg-type]
400400
coords=ac_extractor.get_coords().reshape(-1, 3),
401401
coords_are_cartesian=False,
402402
properties=properties,
@@ -420,7 +420,7 @@ def from_file(cls, filename: PathLike, mag: bool = False) -> Self:
420420
AtomConfig object.
421421
"""
422422
with zopen(filename, mode="rt", encoding="utf-8") as file:
423-
return cls.from_str(data=file.read(), mag=mag)
423+
return cls.from_str(data=file.read(), mag=mag) # type:ignore[arg-type]
424424

425425
@classmethod
426426
def from_dict(cls, dct: dict) -> Self:
@@ -468,7 +468,7 @@ def get_str(self) -> str:
468468
def write_file(self, filename: PathLike, **kwargs):
469469
"""Write AtomConfig to a file."""
470470
with zopen(filename, mode="wt", encoding="utf-8") as file:
471-
file.write(self.get_str(**kwargs))
471+
file.write(self.get_str(**kwargs)) # type:ignore[arg-type]
472472

473473
def as_dict(self):
474474
"""
@@ -696,4 +696,4 @@ def get_hsp_row_str(label: str, index: int, coordinate: float) -> str:
696696
def write_file(self, filename: PathLike):
697697
"""Write HighSymmetryPoint to a file."""
698698
with zopen(filename, mode="wt", encoding="utf-8") as file:
699-
file.write(self.get_str())
699+
file.write(self.get_str()) # type:ignore[arg-type]

src/pymatgen/io/pwmat/outputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def _parse_kpt(self) -> tuple[np.ndarray, np.ndarray, dict[str, np.ndarray]]:
258258
row_idx: int = LineLocator.locate_all_lines(self.filename, content)[0]
259259
kpts: np.ndarray = np.zeros((self._num_kpts, 3))
260260
kpts_weight: np.ndarray = np.zeros(self._num_kpts)
261-
hsps: dict[str, np.array] = {}
261+
hsps: dict[str, np.ndarray] = {}
262262
for ii in range(num_rows):
263263
# 0.00000 0.00000 0.00000 0.03704 G
264264
tmp_row_lst: list[str] = linecache.getline(str(self.filename), row_idx + ii + 1).split()

src/pymatgen/io/xr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def write_file(self, filename: str | Path) -> None:
6969
filename (str): name of the file to write to.
7070
"""
7171
with zopen(filename, mode="wt", encoding="utf-8") as file:
72-
file.write(str(self) + "\n")
72+
file.write(str(self) + "\n") # type:ignore[arg-type]
7373

7474
@classmethod
7575
def from_str(cls, string: str, use_cores: bool = True, thresh: float = 1e-4) -> Self:
@@ -156,4 +156,4 @@ def from_file(cls, filename: str | Path, use_cores: bool = True, thresh: float =
156156
file.
157157
"""
158158
with zopen(filename, mode="rt", encoding="utf-8") as file:
159-
return cls.from_str(file.read(), use_cores=use_cores, thresh=thresh)
159+
return cls.from_str(file.read(), use_cores=use_cores, thresh=thresh) # type:ignore[arg-type]

0 commit comments

Comments
 (0)