diff --git a/changelog.d/951.change.rst b/changelog.d/951.change.rst new file mode 100644 index 000000000..24303f6a9 --- /dev/null +++ b/changelog.d/951.change.rst @@ -0,0 +1,3 @@ +The error signature of _InValidator has been completed, +it now includes the attribute, +options and value as proclaimed in the docstring of _in(). diff --git a/src/attr/validators.py b/src/attr/validators.py index 6a1e198f8..3a4e72823 100644 --- a/src/attr/validators.py +++ b/src/attr/validators.py @@ -299,7 +299,10 @@ def __call__(self, inst, attr, value): raise ValueError( "'{name}' must be in {options!r} (got {value!r})".format( name=attr.name, options=self.options, value=value - ) + ), + attr, + self.options, + value, ) def __repr__(self): diff --git a/tests/test_validators.py b/tests/test_validators.py index f3fe69cc1..3bec62b03 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -471,7 +471,12 @@ def test_fail(self): a = simple_attr("test") with pytest.raises(ValueError) as e: v(None, a, None) - assert ("'test' must be in [1, 2, 3] (got None)",) == e.value.args + assert ( + "'test' must be in [1, 2, 3] (got None)", + a, + [1, 2, 3], + None, + ) == e.value.args def test_fail_with_string(self): """ @@ -482,7 +487,12 @@ def test_fail_with_string(self): a = simple_attr("test") with pytest.raises(ValueError) as e: v(None, a, None) - assert ("'test' must be in 'abc' (got None)",) == e.value.args + assert ( + "'test' must be in 'abc' (got None)", + a, + "abc", + None, + ) == e.value.args def test_repr(self): """