diff --git a/changelog.d/1410.change.md b/changelog.d/1410.change.md new file mode 100644 index 000000000..0536da8f5 --- /dev/null +++ b/changelog.d/1410.change.md @@ -0,0 +1 @@ +The error message if an attribute has both an annotation and a type argument will now disclose _what_ attribute seems to be the problem. diff --git a/src/attr/_make.py b/src/attr/_make.py index 0c5aa0bd6..7439dc2ad 100644 --- a/src/attr/_make.py +++ b/src/attr/_make.py @@ -2491,7 +2491,7 @@ def from_counting_attr(cls, name: str, ca: _CountingAttr, type=None): if type is None: type = ca.type elif ca.type is not None: - msg = "Type annotation and type argument cannot both be present" + msg = f"Type annotation and type argument cannot both be present for '{name}'." raise ValueError(msg) return cls( name, diff --git a/tests/test_annotations.py b/tests/test_annotations.py index f37a1c0b0..5c6296634 100644 --- a/tests/test_annotations.py +++ b/tests/test_annotations.py @@ -62,7 +62,7 @@ class C: x: int = attr.ib(type=int) assert ( - "Type annotation and type argument cannot both be present", + "Type annotation and type argument cannot both be present for 'x'.", ) == e.value.args def test_typing_annotations(self):