Skip to content

Commit

Permalink
fix print in assert msg returning None, so empty msg
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Aug 8, 2024
1 parent a3b0ddb commit 0e90789
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
5 changes: 2 additions & 3 deletions src/pymatgen/transformations/transformation_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/pymatgen/util/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
__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:
string_list: List of strings
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
Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 0e90789

Please sign in to comment.