From db1cbe61c54f9fd21219ae21f5894437868aa2ab Mon Sep 17 00:00:00 2001 From: Sean Kavanagh Date: Fri, 17 Jan 2025 10:45:56 +0000 Subject: [PATCH] Typing --- src/pymatgen/core/composition.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pymatgen/core/composition.py b/src/pymatgen/core/composition.py index 840a787dfc0..9411f06deac 100644 --- a/src/pymatgen/core/composition.py +++ b/src/pymatgen/core/composition.py @@ -173,7 +173,7 @@ def __init__(self, *args, strict: bool = False, **kwargs) -> None: else: elem_map = dict(*args, **kwargs) # type: ignore[assignment] elem_amt = {} - self._n_atoms = 0 + self._n_atoms: int | float = 0 for key, val in elem_map.items(): if val < -type(self).amount_tolerance and not self.allow_negative: raise ValueError("Amounts in Composition cannot be negative!") @@ -184,7 +184,7 @@ def __init__(self, *args, strict: bool = False, **kwargs) -> None: if strict and not self.valid: raise ValueError(f"Composition is not valid, contains: {', '.join(map(str, self.elements))}") - def __getitem__(self, key: SpeciesLike) -> float: + def __getitem__(self, key: SpeciesLike) -> int | float: try: sp = get_el_sp(key) if isinstance(sp, Species): @@ -202,7 +202,7 @@ def __len__(self) -> int: def __iter__(self) -> Iterator[Species | Element | DummySpecies]: return iter(self._data) - def items(self) -> ItemsView[Species | Element | DummySpecies, float]: + def items(self) -> ItemsView[Species | Element | DummySpecies, int | float]: """Returns Dict.items() for the Composition dict.""" return self._data.items()