Skip to content

Commit

Permalink
Improve parameter type handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippThoelke committed Jul 14, 2024
1 parent d7db383 commit 8f4b536
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/goofi/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ class Param(ABC):
def __post_init__(self):
if self._value is None:
self._value = self.default()

if not isinstance(self._value, type(self.default())):
raise TypeError(f"Expected {type(self.default())}, got {type(self._value)}")
if isinstance(self.default(), float) and isinstance(self._value, int):
# it's okay if we wanted a float but got int
self._value = float(self._value)
else:
raise TypeError(
f"Parameter {self.__class__.__name__} expected type {type(self.default())} but got {type(self._value)}."
)

@staticmethod
@abstractmethod
Expand Down

0 comments on commit 8f4b536

Please sign in to comment.