From 0e907899f4ef0c6ffe0fc70a8ef4fef924069eea Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Thu, 8 Aug 2024 19:38:18 -0400 Subject: [PATCH] fix print in assert msg returning None, so empty msg --- src/pymatgen/core/periodic_table.py | 4 ++-- src/pymatgen/io/vasp/inputs.py | 6 ++---- src/pymatgen/transformations/transformation_abc.py | 5 ++--- src/pymatgen/util/io_utils.py | 6 +++--- tests/core/test_periodic_table.py | 6 +++--- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/pymatgen/core/periodic_table.py b/src/pymatgen/core/periodic_table.py index d6992dc3c15..3d465f5eeda 100644 --- a/src/pymatgen/core/periodic_table.py +++ b/src/pymatgen/core/periodic_table.py @@ -476,7 +476,7 @@ def parse_orbital(orb_str): @property def n_electrons(self) -> int: """Total number of electrons in the Element.""" - return sum([t[-1] for t in self.full_electronic_structure]) + return sum(t[-1] for t in self.full_electronic_structure) @property def valence(self) -> tuple[int | np.nan, int]: @@ -1180,7 +1180,7 @@ def parse_orbital(orb_str): @property def n_electrons(self) -> int: """Total number of electrons in the Species.""" - return sum([t[-1] for t in self.full_electronic_structure]) + return sum(t[-1] for t in self.full_electronic_structure) # NOTE - copied exactly from Element. Refactoring / inheritance may improve # robustness diff --git a/src/pymatgen/io/vasp/inputs.py b/src/pymatgen/io/vasp/inputs.py index 9875b1616e1..351dbdcaefd 100644 --- a/src/pymatgen/io/vasp/inputs.py +++ b/src/pymatgen/io/vasp/inputs.py @@ -1465,10 +1465,8 @@ def automatic_linemode(cls, divisions: int, ibz: HighSymmKpath) -> Self: kpoints.append(ibz.kpath["kpoints"][path[0]]) labels.append(path[0]) for i in range(1, len(path) - 1): - kpoints.append(ibz.kpath["kpoints"][path[i]]) - labels.append(path[i]) - kpoints.append(ibz.kpath["kpoints"][path[i]]) - labels.append(path[i]) + kpoints += [ibz.kpath["kpoints"][path[i]]] * 2 + labels += [path[i]] * 2 kpoints.append(ibz.kpath["kpoints"][path[-1]]) labels.append(path[-1]) diff --git a/src/pymatgen/transformations/transformation_abc.py b/src/pymatgen/transformations/transformation_abc.py index 1ed44ac4faf..59a4163345b 100644 --- a/src/pymatgen/transformations/transformation_abc.py +++ b/src/pymatgen/transformations/transformation_abc.py @@ -3,7 +3,7 @@ from __future__ import annotations import abc -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any from monty.json import MSONable @@ -22,7 +22,7 @@ class AbstractTransformation(MSONable, abc.ABC): """Abstract transformation class.""" @abc.abstractmethod - def apply_transformation(self, structure: Structure): + def apply_transformation(self, structure: Structure) -> Structure | list[dict[str, Any]]: """Apply the transformation to a structure. Depending on whether a transformation is one-to-many, there may be an option to return a ranked list of structures. @@ -46,7 +46,6 @@ def apply_transformation(self, structure: Structure): be stored in the transformation_parameters dictionary in the transmuted structure class. """ - return @property def inverse(self) -> AbstractTransformation | None: diff --git a/src/pymatgen/util/io_utils.py b/src/pymatgen/util/io_utils.py index 3fc6074841f..47e543bbf89 100644 --- a/src/pymatgen/util/io_utils.py +++ b/src/pymatgen/util/io_utils.py @@ -16,7 +16,7 @@ __date__ = "Sep 23, 2011" -def clean_lines(string_list, remove_empty_lines=True): +def clean_lines(string_list, remove_empty_lines=True) -> list[str]: """Strips whitespace, carriage returns and empty lines from a list of strings. Args: @@ -24,8 +24,8 @@ def clean_lines(string_list, remove_empty_lines=True): remove_empty_lines: Set to True to skip lines which are empty after stripping. - Returns: - List of clean strings with no whitespaces. + Yields: + list: clean strings with no whitespaces. """ for s in string_list: clean_s = s diff --git a/tests/core/test_periodic_table.py b/tests/core/test_periodic_table.py index d350b2596a7..88a6fbcabfc 100644 --- a/tests/core/test_periodic_table.py +++ b/tests/core/test_periodic_table.py @@ -680,9 +680,9 @@ def test_species_electronic_structure(self): for ox in el.common_oxidation_states: if str(el) == "H" and ox == 1: continue - n_electron_el = sum([orb[-1] for orb in el.full_electronic_structure]) - n_electron_sp = sum([orb[-1] for orb in Species(el, ox).full_electronic_structure]) - assert n_electron_el - n_electron_sp == ox, print(f"Failure for {el} {ox}") + n_electron_el = sum(orb[-1] for orb in el.full_electronic_structure) + n_electron_sp = sum(orb[-1] for orb in Species(el, ox).full_electronic_structure) + assert n_electron_el - n_electron_sp == ox, f"Failure for {el} {ox}" def test_get_el_sp():