Skip to content

Commit

Permalink
Add type checking based on mypy (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen authored Nov 30, 2024
1 parent 93f048b commit 937b16e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: MyPy

on:
push:
branches: [ main ]
pull_request:

jobs:
mypy:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
architecture: x64
- name: Checkout
uses: actions/checkout@v4
- name: Install mypy
run: pip install mypy
- name: Test
run: mypy --ignore-missing-imports ${{ github.event.repository.name }}
2 changes: 1 addition & 1 deletion pyiron_dataclasses/v1/atomistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Cell:
@dataclass
class Structure:
dimension: int
indices: np.array
indices: np.ndarray
info: dict
positions: np.ndarray # N_atoms * 3 [Angstrom]
species: List[str]
Expand Down
14 changes: 10 additions & 4 deletions pyiron_dataclasses/v1/converter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Callable, Union

from pint import UnitRegistry

from pyiron_dataclasses.v1.atomistic import (
Expand Down Expand Up @@ -61,7 +63,7 @@
)


def get_dataclass(job_dict):
def get_dataclass(job_dict: dict) -> Callable:
funct_dict = {
"<class 'pyiron_atomistics.lammps.lammps.Lammps'>": _convert_lammps_job_dict,
"<class 'pyiron_atomistics.sphinx.sphinx.Sphinx'>": _convert_sphinx_job_dict,
Expand Down Expand Up @@ -952,8 +954,8 @@ def recursive_filter(input_value: dict, remove_keys_lst: list) -> dict:
}


def _sort_dictionary_from_datacontainer(input_dict: dict) -> dict:
def recursive_sort(input_value: dict) -> dict:
def _sort_dictionary_from_datacontainer(input_dict: dict) -> Union[dict, list]:
def recursive_sort(input_value: dict) -> Union[dict, list]:
if isinstance(input_value, dict):
return _sort_dictionary_from_datacontainer(input_dict=input_value)
else:
Expand Down Expand Up @@ -986,7 +988,7 @@ def recursive_sort(input_value: dict) -> dict:


def _convert_datacontainer_to_dictionary(data_container_dict: dict) -> dict:
return _sort_dictionary_from_datacontainer(
output_dict = _sort_dictionary_from_datacontainer(
input_dict=_filter_dict(
input_dict=data_container_dict,
remove_keys_lst=[
Expand All @@ -1000,3 +1002,7 @@ def _convert_datacontainer_to_dictionary(data_container_dict: dict) -> dict:
],
)
)
if isinstance(output_dict, dict):
return output_dict
else:
raise TypeError("datacontainer was not converted to a dictionary.")

0 comments on commit 937b16e

Please sign in to comment.