Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete error signature of _InValidator #951

Merged
merged 23 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
68bf50d
feat(ValueError of _InValidator): Add attr, options and value
Apr 11, 2022
470e654
test(tests for _InValidator): Adapt tests to new error signature
Apr 11, 2022
33a3694
test(tests for _InValidator): Redo tests properly
Apr 11, 2022
9fcbee2
docs(Changelog): Add changelog fragment
Apr 11, 2022
2f372b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 11, 2022
32cc097
feat(validators._in()): Add default argument "verbose_value_error=False"
Apr 12, 2022
8a0d27e
test(tests for _InValidator): Add tests for call with "verbose_value_…
Apr 12, 2022
562eb51
docs(Changelog): Adapt changelog fragment
Apr 12, 2022
1b6228a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 12, 2022
4817aca
docs(changelog fragment): Make fragment "breaking" and use semantic n…
May 2, 2022
d40b6e4
docs(docstring of _in()): Use semantic newlines
May 2, 2022
d7cfbd3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 2, 2022
f6bb5c0
docs(changelog fragment): Use semantic newlines
Jun 13, 2022
c1cd68e
Merge remote-tracking branch 'origin/main'
Jun 13, 2022
a2c4f31
Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks"
Jun 13, 2022
eb96ed2
Revert "docs(docstring of _in()): Use semantic newlines"
Jun 13, 2022
e09d2ca
revert(docs(changelog fragment)): Refix changelog fragment
Jun 13, 2022
28cc8bc
Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks"
Jun 13, 2022
26b4234
Revert "docs(Changelog): Adapt changelog fragment"
Jun 13, 2022
c4131b5
Revert "test(tests for _InValidator): Add tests for call with "verbos…
Jun 13, 2022
35ac759
Revert "feat(validators._in()): Add default argument "verbose_value_e…
Jun 13, 2022
67425fe
docs(changelog fragment): Remove old fragment that had the wrong name…
Jun 13, 2022
3c5bfea
Merge branch 'main' into main
hynek Jun 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/951.change.rst
Original file line number Diff line number Diff line change
@@ -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().
5 changes: 4 additions & 1 deletion src/attr/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 12 additions & 2 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down