diff --git a/src/pymatgen/core/composition.py b/src/pymatgen/core/composition.py index d269c247ff9..9b22695a502 100644 --- a/src/pymatgen/core/composition.py +++ b/src/pymatgen/core/composition.py @@ -25,7 +25,7 @@ if TYPE_CHECKING: from collections.abc import Generator, Iterator - from typing import Any, ClassVar + from typing import Any, ClassVar, Literal from typing_extensions import Self @@ -774,17 +774,25 @@ def to_reduced_dict(self) -> dict[str, float]: def to_weight_dict(self) -> dict[str, float]: """ Returns: - dict[str, float] with weight fraction of each component {"Ti": 0.90, "V": 0.06, "Al": 0.04}. + dict[str, float]: weight fractions of each component, e.g. {"Ti": 0.90, "V": 0.06, "Al": 0.04}. """ return {str(el): self.get_wt_fraction(el) for el in self.elements} @property - def to_data_dict(self) -> dict[str, Any]: + def to_data_dict( + self, + ) -> dict[ + Literal["reduced_cell_composition", "unit_cell_composition", "reduced_cell_formula", "elements", "nelements"], + Any, + ]: """ Returns: - A dict with many keys and values relating to Composition/Formula, - including reduced_cell_composition, unit_cell_composition, - reduced_cell_formula, elements and nelements. + dict with the following keys: + - reduced_cell_composition + - unit_cell_composition + - reduced_cell_formula + - elements + - nelements. """ return { "reduced_cell_composition": self.reduced_composition, @@ -802,7 +810,7 @@ def charge(self) -> float | None: """ warnings.warn( "Composition.charge is experimental and may produce incorrect results. Use with " - "caution and open a GitHub issue pinging @janosh to report bad behavior." + "caution and open a GitHub issue pinging @janosh to report bad behavior.", ) oxi_states = [getattr(specie, "oxi_state", None) for specie in self] if {*oxi_states} <= {0, None}: @@ -818,7 +826,7 @@ def charge_balanced(self) -> bool | None: """ warnings.warn( "Composition.charge_balanced is experimental and may produce incorrect results. " - "Use with caution and open a GitHub issue pinging @janosh to report bad behavior." + "Use with caution and open a GitHub issue pinging @janosh to report bad behavior.", ) if self.charge is None: if {getattr(el, "oxi_state", None) for el in self} == {0}: @@ -917,7 +925,7 @@ def replace(self, elem_map: dict[str, str | dict[str, float]]) -> Self: if el in self: warnings.warn( f"Same element ({el}) in both the keys and values of the substitution!" - "This can be ambiguous, so be sure to check your result." + "This can be ambiguous, so be sure to check your result.", ) return type(self)(new_comp)