Skip to content

Commit

Permalink
Fix type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
ndaelman committed Oct 7, 2024
1 parent 93ca194 commit 3c08a87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 9 additions & 11 deletions src/nomad_simulations/schema_packages/model_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def __hash__(self):
return self.representative_variable.__hash__()

@staticmethod
def _check_implemented(func: Callable):
def _check_implemented(func: 'Callable'):
"""
Decorator to restrict the comparison functions to the same class.
"""
Expand Down Expand Up @@ -370,7 +370,7 @@ class Cell(GeometricSpace):
)

@staticmethod
def _generate_comparer(obj) -> Generator[Any, None, None]:
def _generate_comparer(obj: 'Cell') -> 'Generator[Any, None, None]':
try:
return ((HashedPositions(pos)) for pos in obj.positions)
except AttributeError:
Expand Down Expand Up @@ -398,7 +398,7 @@ def is_equal_cell(self, other) -> bool: # TODO: improve naming

def is_ne_cell(self, other) -> bool:
# this does not hold in general, but here we use finite sets
return not self.is_equal_cell(other)
return (not self.is_equal_cell(other))

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)
Expand Down Expand Up @@ -444,9 +444,7 @@ def __init__(self, m_def: 'Section' = None, m_context: 'Context' = None, **kwarg
self.name = self.m_def.name

@staticmethod
def _generate_comparer(
obj,
) -> Generator[Any, None, None]:
def _generate_comparer(obj: 'AtomicCell') -> 'Generator[Any, None, None]':
# presumes `atoms_state` mapping 1-to-1 with `positions` and conserves the order
try:
return (
Expand All @@ -456,7 +454,7 @@ def _generate_comparer(
except AttributeError:
raise NotImplementedError

def to_ase_atoms(self, logger: 'BoundLogger') -> Optional[ase.Atoms]:
def to_ase_atoms(self, logger: 'BoundLogger') -> 'Optional[ase.Atoms]':
"""
Generates an ASE Atoms object with the most basic information from the parsed `AtomicCell`
section (labels, periodic_boundary_conditions, positions, and lattice_vectors).
Expand Down Expand Up @@ -618,8 +616,8 @@ class Symmetry(ArchiveSection):
)

def resolve_analyzed_atomic_cell(
self, symmetry_analyzer: SymmetryAnalyzer, cell_type: str, logger: 'BoundLogger'
) -> Optional[AtomicCell]:
self, symmetry_analyzer: 'SymmetryAnalyzer', cell_type: str, logger: 'BoundLogger'
) -> 'Optional[AtomicCell]':
"""
Resolves the `AtomicCell` section from the `SymmetryAnalyzer` object and the cell_type
(primitive or conventional).
Expand Down Expand Up @@ -663,8 +661,8 @@ def resolve_analyzed_atomic_cell(
return atomic_cell

def resolve_bulk_symmetry(
self, original_atomic_cell: AtomicCell, logger: 'BoundLogger'
) -> tuple[Optional[AtomicCell], Optional[AtomicCell]]:
self, original_atomic_cell: 'AtomicCell', logger: 'BoundLogger'
) -> 'tuple[Optional[AtomicCell], Optional[AtomicCell]]':
"""
Resolves the symmetry of the material being simulated using MatID and the
originally parsed data under original_atomic_cell. It generates two other
Expand Down
4 changes: 2 additions & 2 deletions src/nomad_simulations/schema_packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ def get_composition(children_names: 'list[str]') -> str:
return formula if formula else None


def catch_not_implemented(func: Callable):
def catch_not_implemented(func: 'Callable') -> 'Callable':
"""
Decorator to default comparison functions outside the same class to `False`.
"""

def wrapper(self, other):
def wrapper(self, other) -> bool:
if not isinstance(other, self.__class__):
return False # ? should this throw an error instead?
try:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_model_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ class TestAtomicCell:
), # different position-symbol map
],
)
def test_partial_order(self, cell_1: Cell, cell_2: Cell, result: dict[str, bool]):
def test_partial_order(
self, cell_1: 'Cell', cell_2: 'Cell', result: dict[str, bool]
):
"""
Test the comparison operators of `Cell` and `AtomicCell`.
"""
Expand Down

1 comment on commit 3c08a87

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py15287%57–59
   atoms_state.py1902189%31–33, 219–222, 246, 301–302, 370–371, 373, 555, 567–568, 629–633, 648–652, 659
   basis_set.py2402888%8–9, 122–133, 172–185, 208, 391–395, 417–418, 462–465, 584, 615, 617
   general.py89891%22–25, 139, 203, 313–314, 324
   model_method.py2657771%28–30, 189–192, 195–202, 294–295, 315, 336–357, 373–399, 402–419, 773, 784, 826–833, 871, 890, 970, 1027, 1102, 1216
   model_system.py3283589%45–51, 243, 254, 258, 261, 264, 290, 376–377, 454–455, 635–638, 685–692, 866–867, 1088–1092, 1098–1099, 1107–1108, 1113, 1136
   numerical_settings.py2596176%30–32, 235, 237–238, 241–244, 248–249, 256–259, 268–271, 275–278, 280–283, 288–291, 297–300, 487–514, 589, 624–627, 651, 654, 699, 701–704, 708, 712, 759, 763–784, 839–840, 907
   outputs.py1201092%27–28, 270–273, 313–316, 341, 343, 380, 399
   physical_property.py102793%38–40, 220, 349–351
   variables.py861286%26–28, 116, 139, 163, 185, 207, 229, 251, 274, 294
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%26–28, 153–154
   band_structure.py1232580%27–29, 250–283, 296, 303, 339–340, 343, 390–391, 396
   energies.py42979%25–27, 54, 75, 100, 121, 137, 152
   fermi_surface.py17476%25–27, 58
   forces.py22673%26–28, 55, 75, 98
   greens_function.py991387%25–27, 228–229, 232, 253–254, 257, 278–279, 282, 418
   hopping_matrix.py29583%25–27, 76, 112
   permittivity.py48883%25–27, 115–123
   spectral_profile.py26012851%27–29, 75–78, 113–116, 217–318, 374–386, 411–414, 434, 439–442, 484–520, 544, 591–594, 610–611, 616–622
   thermodynamics.py752764%25–27, 53, 74, 90, 99, 108, 119, 128, 155, 165, 175, 190–192, 195, 211, 231–233, 236, 252, 272–274, 277
src/nomad_simulations/schema_packages/utils
   utils.py801779%27–32, 86–95, 104–105, 110, 113, 190–191
TOTAL256651280% 

Tests Skipped Failures Errors Time
397 0 💤 0 ❌ 0 🔥 6.014s ⏱️

Please sign in to comment.