Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added type hints for WeightWindows class #2462

Merged
merged 3 commits into from
Apr 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions openmc/weight_windows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations
from collections.abc import Iterable
from numbers import Real, Integral
from typing import Iterable, List

from xml.etree import ElementTree as ET
import numpy as np
Expand Down Expand Up @@ -146,7 +148,7 @@ def __init__(self, mesh, lower_ww_bounds,
self.max_split = max_split
self.weight_cutoff = weight_cutoff

def __repr__(self):
def __repr__(self) -> str:
string = type(self).__name__ + '\n'
string += '{: <16}=\t{}\n'.format('\tID', self._id)
string += '{: <16}=\t{}\n'.format('\tMesh:', self.mesh)
Expand All @@ -159,7 +161,7 @@ def __repr__(self):
string += '{: <16}=\t{}\n'.format('\tWeight Cutoff', self._weight_cutoff)
return string

def __eq__(self, other):
def __eq__(self, other) -> bool:
# ensure that `other` is a WeightWindows object
if not isinstance(other, WeightWindows):
return False
Expand Down Expand Up @@ -189,7 +191,7 @@ def __eq__(self, other):
return True

@property
def mesh(self):
def mesh(self) -> MeshBase:
return self._mesh

@mesh.setter
Expand All @@ -198,7 +200,7 @@ def mesh(self, mesh):
self._mesh = mesh

@property
def particle_type(self):
def particle_type(self) -> str:
return self._particle_type

@particle_type.setter
Expand All @@ -207,7 +209,7 @@ def particle_type(self, pt):
self._particle_type = pt

@property
def energy_bounds(self):
def energy_bounds(self) -> Iterable[Real]:
return self._energy_bounds

@energy_bounds.setter
Expand All @@ -216,13 +218,13 @@ def energy_bounds(self, bounds):
self._energy_bounds = np.asarray(bounds)

@property
def num_energy_bins(self):
def num_energy_bins(self) -> int:
if self.energy_bounds is None:
raise ValueError('Energy bounds are not set')
return self.energy_bounds.size - 1

@property
def lower_ww_bounds(self):
def lower_ww_bounds(self) -> np.ndarray:
return self._lower_ww_bounds

@lower_ww_bounds.setter
Expand All @@ -241,7 +243,7 @@ def lower_ww_bounds(self, bounds):
self._lower_ww_bounds = bounds

@property
def upper_ww_bounds(self):
def upper_ww_bounds(self) -> np.ndarray:
return self._upper_ww_bounds

@upper_ww_bounds.setter
Expand All @@ -260,7 +262,7 @@ def upper_ww_bounds(self, bounds):
self._upper_ww_bounds = bounds

@property
def survival_ratio(self):
def survival_ratio(self) -> float:
return self._survival_ratio

@survival_ratio.setter
Expand All @@ -270,7 +272,7 @@ def survival_ratio(self, val):
self._survival_ratio = val

@property
def max_lower_bound_ratio(self):
def max_lower_bound_ratio(self) -> float:
return self._max_lower_bound_ratio

@max_lower_bound_ratio.setter
Expand All @@ -280,7 +282,7 @@ def max_lower_bound_ratio(self, val):
self._max_lower_bound_ratio = val

@property
def max_split(self):
def max_split(self) -> int:
return self._max_split

@max_split.setter
Expand All @@ -289,7 +291,7 @@ def max_split(self, val):
self._max_split = val

@property
def weight_cutoff(self):
def weight_cutoff(self) -> float:
return self._weight_cutoff

@weight_cutoff.setter
Expand All @@ -298,7 +300,7 @@ def weight_cutoff(self, cutoff):
cv.check_greater_than('Weight cutoff', cutoff, 0.0, True)
self._weight_cutoff = cutoff

def to_xml_element(self):
def to_xml_element(self) -> ET.Element:
"""Return an XML representation of the weight window settings

Returns
Expand Down Expand Up @@ -341,7 +343,7 @@ def to_xml_element(self):
return element

@classmethod
def from_xml_element(cls, elem, root):
def from_xml_element(cls, elem, root) -> WeightWindows:
"""Generate weight window settings from an XML element

Parameters
Expand Down Expand Up @@ -396,7 +398,7 @@ def from_xml_element(cls, elem, root):
)

@classmethod
def from_hdf5(cls, group, meshes):
def from_hdf5(cls, group, meshes) -> WeightWindows:
"""Create weight windows from HDF5 group

Parameters
Expand Down Expand Up @@ -441,7 +443,7 @@ def from_hdf5(cls, group, meshes):
)


def wwinp_to_wws(path):
def wwinp_to_wws(path) -> List[WeightWindows]:
"""Create WeightWindows instances from a wwinp file

.. versionadded:: 0.13.1
Expand Down