Skip to content

Commit dae7d43

Browse files
committed
More typing cleanups.
1 parent 8ffeade commit dae7d43

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
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"] #, "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', 'src/pymatgen/apps', 'src/pymatgen/vis', "src/pymatgen/alchemy"]
305+
exclude = ['src/pymatgen/analysis', 'src/pymatgen/io', 'src/pymatgen/cli', 'src/pymatgen/electronic_structure', 'src/pymatgen/phonon', 'src/pymatgen/vis', "src/pymatgen/alchemy"]
306306
plugins = ["numpy.typing.mypy_plugin"]
307307

308308
[[tool.mypy.overrides]]

src/pymatgen/apps/battery/battery_abc.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
from monty.json import MSONable
1515
from scipy.constants import N_A
1616

17-
from pymatgen.core import Composition, Element
17+
from pymatgen.core import Composition
1818

1919
if TYPE_CHECKING:
20-
from pymatgen.entries.computed_entries import ComputedEntry
20+
from pymatgen.entries import Entry
21+
from pymatgen.util.typing import SpeciesLike
2122

2223
__author__ = "Anubhav Jain, Shyue Ping Ong"
2324
__copyright__ = "Copyright 2012, The Materials Project"
@@ -53,7 +54,7 @@ class AbstractVoltagePair(MSONable):
5354
vol_discharge: float
5455
frac_charge: float
5556
frac_discharge: float
56-
working_ion_entry: ComputedEntry
57+
working_ion_entry: Entry
5758
framework_formula: str
5859

5960
def __post_init__(self):
@@ -62,7 +63,7 @@ def __post_init__(self):
6263
self.framework_formula = fw.reduced_formula
6364

6465
@property
65-
def working_ion(self) -> Element:
66+
def working_ion(self) -> SpeciesLike:
6667
"""Working ion as pymatgen Element object."""
6768
return self.working_ion_entry.elements[0]
6869

@@ -128,7 +129,7 @@ class AbstractElectrode(Sequence, MSONable):
128129
"""
129130

130131
voltage_pairs: tuple[AbstractVoltagePair, ...]
131-
working_ion_entry: ComputedEntry
132+
working_ion_entry: Entry
132133
framework_formula: str # should be made into Composition whenever the as_dict and from dict are fixed
133134

134135
def __post_init__(self):

src/pymatgen/apps/battery/insertion_battery.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
from pymatgen.apps.battery.battery_abc import AbstractElectrode, AbstractVoltagePair
1616
from pymatgen.core import Composition, Element
1717
from pymatgen.core.units import Charge, Time
18-
from pymatgen.entries.computed_entries import ComputedEntry, ComputedStructureEntry
18+
from pymatgen.entries.computed_entries import ComputedEntry
1919

2020
if TYPE_CHECKING:
2121
from collections.abc import Iterable
2222

2323
from typing_extensions import Self
2424

25+
from pymatgen.entries import Entry
26+
2527
__author__ = "Anubhav Jain, Shyue Ping Ong"
2628
__copyright__ = "Copyright 2012, The Materials Project"
2729

@@ -33,14 +35,14 @@ class InsertionElectrode(AbstractElectrode):
3335
insertion battery electrode.
3436
"""
3537

36-
stable_entries: Iterable[ComputedEntry]
37-
unstable_entries: Iterable[ComputedEntry]
38+
stable_entries: Iterable[Entry]
39+
unstable_entries: Iterable[Entry]
3840

3941
@classmethod
4042
def from_entries(
4143
cls,
42-
entries: Iterable[ComputedEntry | ComputedStructureEntry],
43-
working_ion_entry: ComputedEntry | ComputedStructureEntry | PDEntry,
44+
entries: Iterable[Entry],
45+
working_ion_entry: Entry,
4446
strip_structures: bool = False,
4547
) -> Self:
4648
"""Create a new InsertionElectrode.
@@ -80,15 +82,15 @@ def from_entries(
8082
# Set an artificial high energy for each element for convex hull generation
8183
element_energy = max(entry.energy_per_atom for entry in entries) + 10
8284

83-
pdentries: list[ComputedEntry | ComputedStructureEntry | PDEntry] = []
85+
pdentries: list[Entry] = []
8486
pdentries.extend(entries)
8587
pdentries.extend([PDEntry(Composition({el: 1}), element_energy) for el in elements])
8688

8789
# Make phase diagram to determine which entries are stable vs. unstable.
8890
# For each working ion concentration, we want one stable entry
8991
# to use in forming voltage pairs. PhaseDiagram allows for easy comparison
9092
# of entry energies.
91-
pd = PhaseDiagram(pdentries)
93+
pd = PhaseDiagram(pdentries) # type:ignore[arg-type]
9294

9395
def lifrac(e):
9496
return e.composition.get_atomic_fraction(_working_ion)
@@ -364,7 +366,7 @@ def from_dict_legacy(cls, dct) -> Self:
364366
Returns:
365367
InsertionElectrode
366368
"""
367-
return InsertionElectrode(
369+
return InsertionElectrode( # type:ignore[return-value,call-arg]
368370
MontyDecoder().process_decoded(dct["entries"]),
369371
MontyDecoder().process_decoded(dct["working_ion_entry"]),
370372
)
@@ -387,7 +389,7 @@ class InsertionVoltagePair(AbstractVoltagePair):
387389
entry_discharge: ComputedEntry
388390

389391
@classmethod
390-
def from_entries(cls, entry1, entry2, working_ion_entry) -> Self:
392+
def from_entries(cls, entry1, entry2, working_ion_entry) -> InsertionVoltagePair:
391393
"""
392394
Args:
393395
entry1: Entry corresponding to one of the entries in the voltage step.

src/pymatgen/apps/borg/hive.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(
8989
self,
9090
inc_structure: bool = False,
9191
parameters: list[str] | None = None,
92-
data: list[str] | None = None,
92+
data: dict | None = None,
9393
) -> None:
9494
"""
9595
Args:
@@ -113,7 +113,7 @@ def __init__(
113113
}
114114
if parameters:
115115
self._parameters.update(parameters)
116-
self._data = data or []
116+
self._data = data or {}
117117

118118
def __str__(self) -> str:
119119
return "VaspToComputedEntryDrone"
@@ -132,10 +132,9 @@ def assimilate(self, path: PathLike) -> ComputedStructureEntry | ComputedEntry |
132132
filepath = glob(f"{path}/relax2/vasprun.xml*")[0]
133133
else:
134134
vasprun_files = glob(f"{path}/vasprun.xml*")
135-
filepath = None
136135
if len(vasprun_files) == 1:
137136
filepath = vasprun_files[0]
138-
elif len(vasprun_files) > 1:
137+
else:
139138
# Since multiple files are ambiguous, we will always read
140139
# the last one alphabetically.
141140
filepath = max(vasprun_files)
@@ -147,7 +146,7 @@ def assimilate(self, path: PathLike) -> ComputedStructureEntry | ComputedEntry |
147146
logger.debug(f"error in {filepath}: {exc}")
148147
return None
149148

150-
return vasp_run.get_computed_entry(self._inc_structure, parameters=self._parameters, data=self._data)
149+
return vasp_run.get_computed_entry(self._inc_structure, parameters=list(self._parameters), data=self._data)
151150

152151
# entry.parameters["history"] = _get_transformation_history(path)
153152

@@ -280,7 +279,7 @@ def assimilate(self, path: PathLike) -> ComputedStructureEntry | ComputedEntry |
280279
initial_vol = poscar.structure.volume
281280
final_vol = contcar.structure.volume
282281
delta_volume = final_vol / initial_vol - 1
283-
data = {"filename": path, "delta_volume": delta_volume}
282+
data: dict[str, Any] = {"filename": path, "delta_volume": delta_volume}
284283
if "DYNMAT" in files_to_parse:
285284
dynmat = Dynmat(files_to_parse["DYNMAT"])
286285
data["phonon_frequencies"] = dynmat.get_phonon_frequencies()

src/pymatgen/apps/borg/queen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def save_data(self, filename: PathLike) -> None:
104104
or bz2 compression will be applied.
105105
"""
106106
with zopen(filename, mode="wt", encoding="utf-8") as file:
107-
json.dump(list(self._data), file, cls=MontyEncoder)
107+
json.dump(list(self._data), file, cls=MontyEncoder) # type:ignore[arg-type]
108108

109109
def load_data(self, filename: PathLike) -> None:
110110
"""Load assimilated data from a file."""

src/pymatgen/command_line/enumlib_caller.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ def _get_structures(self, num_structs: int) -> list[Structure]:
365365
)
366366
inv_org_latt = np.linalg.inv(original_latt.matrix)
367367
else:
368-
ordered_structure = inv_org_latt = None
368+
ordered_structure = None # type: ignore[assignment]
369+
inv_org_latt = None # type: ignore[assignment]
369370

370371
for file in glob("vasp.*"):
371372
with open(file, encoding="utf-8") as _file:

0 commit comments

Comments
 (0)