Skip to content

Commit 5cd8f84

Browse files
committed
Update interp function validation to asserts
1 parent 559f37a commit 5cd8f84

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

parcels/field.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,35 @@ def _interp_template(
107107
"""Template function used for the signature check of the lateral interpolation methods."""
108108
return 0.0
109109

110-
def _validate_interp_function(self, func: Callable) -> bool:
110+
def _validate_interp_function(self, func: Callable) -> None:
111111
"""Ensures that the function has the correct signature."""
112112
template_sig = inspect.signature(self._interp_template)
113113
func_sig = inspect.signature(func)
114114

115115
if len(template_sig.parameters) != len(func_sig.parameters):
116-
return False
116+
raise ValueError(
117+
f"Interpolation function must have {len(template_sig.parameters)} parameters, got {len(func_sig.parameters)}"
118+
)
117119

118120
for (_name1, param1), (_name2, param2) in zip(
119121
template_sig.parameters.items(), func_sig.parameters.items(), strict=False
120122
):
121123
if param1.kind != param2.kind:
122-
return False
124+
raise ValueError(
125+
f"Parameter '{_name2}' has incorrect parameter kind. Expected {param1.kind}, got {param2.kind}"
126+
)
123127
if param1.annotation != param2.annotation:
124-
return False
128+
raise ValueError(
129+
f"Parameter '{_name2}' has incorrect type annotation. Expected {param1.annotation}, got {param2.annotation}"
130+
)
125131

126132
return_annotation = func_sig.return_annotation
127133
template_return = template_sig.return_annotation
128134

129135
if return_annotation != template_return:
130-
return False
131-
132-
return True
136+
raise ValueError(
137+
f"Interpolation function has incorrect return type. Expected {template_return}, got {return_annotation}"
138+
)
133139

134140
def __init__(
135141
self,

0 commit comments

Comments
 (0)