Skip to content

Commit 2be39aa

Browse files
committed
Validate not-None input directly.
1 parent 1df0d98 commit 2be39aa

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/skillmodels/constraints.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ class FixedConstraintWithValue(om.FixedConstraint):
4040
value: float | None = None
4141
"""Value to enforce on the parameter."""
4242

43+
def __post_init__(self) -> None:
44+
"""Validate that `loc` and `value` are not None."""
45+
if self.loc is None:
46+
msg = "loc must not be None"
47+
raise TypeError(msg)
48+
if self.value is None:
49+
msg = "value must not be None"
50+
raise TypeError(msg)
51+
4352

4453
def get_constraints(
4554
dimensions: Dimensions,
@@ -490,10 +499,7 @@ def enforce_fixed_constraints(
490499
message="indexing past lexsort depth may impact performance.",
491500
)
492501
for constraint in constraints:
493-
if (
494-
isinstance(constraint, FixedConstraintWithValue)
495-
and constraint.value is not None
496-
):
502+
if isinstance(constraint, FixedConstraintWithValue):
497503
params.loc[constraint.loc, "value"] = constraint.value
498504

499505
# Setting via loc may expand the index, so reduce to the original index

0 commit comments

Comments
 (0)