Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 7, 2024
1 parent 154bc79 commit 82ccbed
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 24 deletions.
4 changes: 2 additions & 2 deletions masci_tools/io/common_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_outfile_txt(outfile):
return tmptxt


def skipHeader(seq: Iterable[Any], n: int) -> Generator[Any, None, None]:
def skipHeader(seq: Iterable[Any], n: int) -> Generator[Any]:
"""Iterate over a sequence skipping the first n elements
Args:
Expand Down Expand Up @@ -617,7 +617,7 @@ def find_symmetry_relation(from_pos: VectorType,
:raises ValueError: If no symmetry relation is found
"""

def lattice_shifts() -> Generator[np.ndarray, None, None]:
def lattice_shifts() -> Generator[np.ndarray]:
for i in range(-2, 3):
for j in range(-2, 3):
for k in range(-2, 3):
Expand Down
6 changes: 3 additions & 3 deletions masci_tools/io/fleur_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def find(self, name: str, **kwargs: Any) -> _GeneratorContextManager[_EvalContex
raise ValueError(f'No nodes found for name {name}')

@contextmanager
def nested(self, etree_or_element: XMLLike) -> Generator[_EvalContext, None, None]:
def nested(self, etree_or_element: XMLLike) -> Generator[_EvalContext]:
"""
Create a nested context from the current one
inheriting the schema_dict, constants and logger only replacing the
Expand All @@ -534,7 +534,7 @@ def nested(self, etree_or_element: XMLLike) -> Generator[_EvalContext, None, Non
"""
yield _EvalContext(etree_or_element, self.schema_dict, self.constants, logger=self.logger)

def iter(self, name: str, **kwargs: Any) -> Generator[_EvalContext, None, None]:
def iter(self, name: str, **kwargs: Any) -> Generator[_EvalContext]:
"""
Finds all elements for the given name and constraints and gives nested
contexts for these elements to be iterated over,
Expand Down Expand Up @@ -572,7 +572,7 @@ def iter(self, name: str, **kwargs: Any) -> Generator[_EvalContext, None, None]:
def FleurXMLContext(etree_or_element: XMLLike | etree.XPathElementEvaluator,
schema_dict: fleur_schema.InputSchemaDict | fleur_schema.OutputSchemaDict,
constants: dict[str, float] | None = None,
logger: logging.Logger | None = None) -> Generator[_EvalContext, None, None]:
logger: logging.Logger | None = None) -> Generator[_EvalContext]:
"""
Contextmanager to hold the relevant datastructures for evaluating values from XML files
Expand Down
16 changes: 8 additions & 8 deletions masci_tools/tools/greensfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ def listElements(hdffile: FileLike, show: bool = False) -> list[GreensfElement]:

def select_elements_from_file(hdffile: FileLike,
show: bool = False,
**selection_params: Any) -> Generator[GreensFunction, None, None]:
**selection_params: Any) -> Generator[GreensFunction]:
"""
Construct the green's function matching specified criteria from a given ``greensf.hdf`` file
Expand All @@ -1088,7 +1088,7 @@ def select_elements_from_file(hdffile: FileLike,
elements = listElements(hdffile, show=show)
found_elements = select_element_indices(elements, show=show, **selection_params)

def gf_iterator(found_elements: list[int]) -> Generator[GreensFunction, None, None]:
def gf_iterator(found_elements: list[int]) -> Generator[GreensFunction]:
for index in found_elements:
yield GreensFunction.fromFile(hdffile, index=index + 1)

Expand All @@ -1097,7 +1097,7 @@ def gf_iterator(found_elements: list[int]) -> Generator[GreensFunction, None, No

def select_elements(greensfunctions: list[GreensFunction],
show: bool = False,
**selection_params: Any) -> Generator[GreensFunction, None, None]:
**selection_params: Any) -> Generator[GreensFunction]:
"""
Select :py:class:`GreensFunction` objects from a list based on constraints on the
values of their underlying :py:class:`GreensfElement`
Expand All @@ -1112,7 +1112,7 @@ def select_elements(greensfunctions: list[GreensFunction],
elements = [gf.element for gf in greensfunctions]
found_elements = select_element_indices(elements, show=show, **selection_params)

def gf_iterator(found_elements: list[int]) -> Generator[GreensFunction, None, None]:
def gf_iterator(found_elements: list[int]) -> Generator[GreensFunction]:
for index in found_elements:
yield greensfunctions[index]

Expand Down Expand Up @@ -1152,7 +1152,7 @@ def intersite_shells_from_file(hdffile: FileLike,
reference_atom: int,
show: bool = False,
max_shells: int | None = None
) -> Generator[tuple[np.floating[Any], GreensFunction, GreensFunction], None, None]:
) -> Generator[tuple[np.floating[Any], GreensFunction, GreensFunction]]:
"""
Construct the green's function pairs to calculate the Jij exchange constants
for a given reference atom from a given ``greensf.hdf`` file
Expand All @@ -1171,7 +1171,7 @@ def intersite_shells_from_file(hdffile: FileLike,

def shell_iterator(
shells: list[tuple[np.floating[Any], list[tuple[int, int]]]]
) -> Generator[tuple[np.floating[Any], GreensFunction, GreensFunction], None, None]:
) -> Generator[tuple[np.floating[Any], GreensFunction, GreensFunction]]:
for distance, pairs in shells:
for g1, g2 in pairs:
#Plus 1 because the indexing starts at 1 in the hdf file
Expand All @@ -1186,7 +1186,7 @@ def intersite_shells(greensfunctions: list[GreensFunction],
reference_atom: int,
show: bool = False,
max_shells: int | None = None
) -> Generator[tuple[np.floating[Any], GreensFunction, GreensFunction], None, None]:
) -> Generator[tuple[np.floating[Any], GreensFunction, GreensFunction]]:
"""
Construct the green's function pairs to calculate the Jij exchange constants
for a given reference atom from a list of given :py:class:`GreensFunction`
Expand All @@ -1205,7 +1205,7 @@ def intersite_shells(greensfunctions: list[GreensFunction],

def shell_iterator(
shells: list[tuple[np.floating[Any], list[tuple[int, int]]]]
) -> Generator[tuple[np.floating[Any], GreensFunction, GreensFunction], None, None]:
) -> Generator[tuple[np.floating[Any], GreensFunction, GreensFunction]]:
for distance, pairs in shells:
for g1, g2 in pairs:
yield (distance, greensfunctions[g1], greensfunctions[g2])
Expand Down
2 changes: 1 addition & 1 deletion masci_tools/util/case_insensitive_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def __ne__(self, other: object) -> bool:
return super().__ne__({self._norm_key(key) for key in other})
return False

def __iter__(self) -> Generator[T_co, None, None]:
def __iter__(self) -> Generator[T_co]:
for item in super().__iter__():
yield self.original_case[item]

Expand Down
2 changes: 1 addition & 1 deletion masci_tools/vis/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


@contextmanager
def NestedPlotParameters(plotter_object: Plotter) -> Generator[None, None, None]:
def NestedPlotParameters(plotter_object: Plotter) -> Generator[None]:
"""
Contextmanager for nested plot function calls
Will reset function defaults and parameters to previous
Expand Down
63 changes: 54 additions & 9 deletions tests/io/test_fleur_inpgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ def test_write_inpgen_file_defaults_dict(file_regression):

param = 5.43
cell = [[0, param / 2., param / 2.], [param / 2., 0, param / 2.], [param / 2., param / 2., 0]]
kinds = [{'symbols': ('Si',), 'weights': (1.0,), 'mass': 28.0855, 'name': 'Si'}]
kinds = [{
'symbols': ('Si',),
'weights': (1.0,),
'mass': 28.0855,
'name': 'Si'
}]
sites = [{
'position': (0.0, 0.0, 0.0),
'kind_name': 'Si'
Expand All @@ -37,7 +42,12 @@ def test_write_inpgen_file_magmom_str(file_regression):

param = 5.43
cell = [[0, param / 2., param / 2.], [param / 2., 0, param / 2.], [param / 2., param / 2., 0]]
kinds = [{'symbols': ('Si',), 'weights': (1.0,), 'mass': 28.0855, 'name': 'Si'}]
kinds = [{
'symbols': ('Si',),
'weights': (1.0,),
'mass': 28.0855,
'name': 'Si'
}]
sites = [{
'position': (0.0, 0.0, 0.0),
'kind_name': 'Si',
Expand All @@ -63,7 +73,12 @@ def test_write_inpgen_file_magmom_float(file_regression):

param = 5.43
cell = [[0, param / 2., param / 2.], [param / 2., 0, param / 2.], [param / 2., param / 2., 0]]
kinds = [{'symbols': ('Si',), 'weights': (1.0,), 'mass': 28.0855, 'name': 'Si'}]
kinds = [{
'symbols': ('Si',),
'weights': (1.0,),
'mass': 28.0855,
'name': 'Si'
}]
sites = [{
'position': (0.0, 0.0, 0.0),
'kind_name': 'Si',
Expand All @@ -89,7 +104,12 @@ def test_write_inpgen_file_magmom_list(file_regression):

param = 5.43
cell = [[0, param / 2., param / 2.], [param / 2., 0, param / 2.], [param / 2., param / 2., 0]]
kinds = [{'symbols': ('Si',), 'weights': (1.0,), 'mass': 28.0855, 'name': 'Si'}]
kinds = [{
'symbols': ('Si',),
'weights': (1.0,),
'mass': 28.0855,
'name': 'Si'
}]
sites = [{
'position': (0.0, 0.0, 0.0),
'kind_name': 'Si',
Expand All @@ -115,7 +135,12 @@ def test_write_inpgen_file_defaults_dict_filename(file_regression):

param = 5.43
cell = [[0, param / 2., param / 2.], [param / 2., 0, param / 2.], [param / 2., param / 2., 0]]
kinds = [{'symbols': ('Si',), 'weights': (1.0,), 'mass': 28.0855, 'name': 'Si'}]
kinds = [{
'symbols': ('Si',),
'weights': (1.0,),
'mass': 28.0855,
'name': 'Si'
}]
sites = [{
'position': (0.0, 0.0, 0.0),
'kind_name': 'Si'
Expand All @@ -140,7 +165,12 @@ def test_write_inpgen_file_defaults_str(file_regression):

param = 5.43
cell = [[0, param / 2., param / 2.], [param / 2., 0, param / 2.], [param / 2., param / 2., 0]]
kinds = [{'symbols': ('Si',), 'weights': (1.0,), 'mass': 28.0855, 'name': 'Si'}]
kinds = [{
'symbols': ('Si',),
'weights': (1.0,),
'mass': 28.0855,
'name': 'Si'
}]
sites = [{
'position': (0.0, 0.0, 0.0),
'kind_name': 'Si'
Expand Down Expand Up @@ -197,7 +227,12 @@ def test_write_inpgen_file_parameters(file_regression):

param = 5.43
cell = [[0, param / 2., param / 2.], [param / 2., 0, param / 2.], [param / 2., param / 2., 0]]
kinds = [{'symbols': ('Si',), 'weights': (1.0,), 'mass': 28.0855, 'name': 'Si'}]
kinds = [{
'symbols': ('Si',),
'weights': (1.0,),
'mass': 28.0855,
'name': 'Si'
}]
sites = [{
'position': (0.0, 0.0, 0.0),
'kind_name': 'Si'
Expand Down Expand Up @@ -242,7 +277,12 @@ def test_write_inpgen_file_econfig(file_regression):

param = 5.43
cell = [[0, param / 2., param / 2.], [param / 2., 0, param / 2.], [param / 2., param / 2., 0]]
kinds = [{'symbols': ('Si',), 'weights': (1.0,), 'mass': 28.0855, 'name': 'Si'}]
kinds = [{
'symbols': ('Si',),
'weights': (1.0,),
'mass': 28.0855,
'name': 'Si'
}]
sites = [{
'position': (0.0, 0.0, 0.0),
'kind_name': 'Si'
Expand Down Expand Up @@ -289,7 +329,12 @@ def test_write_inpgen_file_soc_qss(file_regression):

param = 5.43
cell = [[0, param / 2., param / 2.], [param / 2., 0, param / 2.], [param / 2., param / 2., 0]]
kinds = [{'symbols': ('Si',), 'weights': (1.0,), 'mass': 28.0855, 'name': 'Si'}]
kinds = [{
'symbols': ('Si',),
'weights': (1.0,),
'mass': 28.0855,
'name': 'Si'
}]
sites = [{
'position': (0.0, 0.0, 0.0),
'kind_name': 'Si'
Expand Down

0 comments on commit 82ccbed

Please sign in to comment.