From 182eb92608993353b77484245ec2e22a5a4bcfe7 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 22 Feb 2025 11:43:05 +0100 Subject: [PATCH 1/2] Mention what argument has both annotation and type argument Fixes #1354 Co-authored-by: SoundsSerious <10334493+SoundsSerious@users.noreply.github.com> --- src/attr/_make.py | 2 +- tests/test_annotations.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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): From e65217c5a1b40bab4903533377cb2e3218d83981 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 22 Feb 2025 11:45:45 +0100 Subject: [PATCH 2/2] Add news fragment --- changelog.d/1410.change.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/1410.change.md 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.