diff --git a/linear_regression.py b/linear_regression.py index 2e8d223..3d99082 100644 --- a/linear_regression.py +++ b/linear_regression.py @@ -21,6 +21,9 @@ class Regression: def predict(self, *, x: int | float = None, y: int | float = None) -> float: """predict a value if x or y is given""" + if x is not None and y is not None: + msg = "predict() expects one keyword argument 'x' or 'y', got both" + raise TypeError(msg) if x is not None: return self.intercept + x * self.coefficient if y is not None: @@ -77,6 +80,9 @@ def test_regression_predict_exceptions(example_data): with pytest.raises(TypeError, match="expects a keyword"): regression.predict() + with pytest.raises(TypeError, match="expects one keyword"): + regression.predict(x=1, y=2) + with pytest.raises(TypeError, match="takes 1 positional argument but"): regression.predict(1)