Skip to content

Commit 1c962d1

Browse files
authored
Mention what argument has both annotation and type argument (#1410)
* Mention what argument has both annotation and type argument Fixes #1354 Co-authored-by: SoundsSerious <[email protected]> * Add news fragment
1 parent 6bde361 commit 1c962d1

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

changelog.d/1410.change.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

src/attr/_make.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2491,7 +2491,7 @@ def from_counting_attr(cls, name: str, ca: _CountingAttr, type=None):
24912491
if type is None:
24922492
type = ca.type
24932493
elif ca.type is not None:
2494-
msg = "Type annotation and type argument cannot both be present"
2494+
msg = f"Type annotation and type argument cannot both be present for '{name}'."
24952495
raise ValueError(msg)
24962496
return cls(
24972497
name,

tests/test_annotations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class C:
6262
x: int = attr.ib(type=int)
6363

6464
assert (
65-
"Type annotation and type argument cannot both be present",
65+
"Type annotation and type argument cannot both be present for 'x'.",
6666
) == e.value.args
6767

6868
def test_typing_annotations(self):

0 commit comments

Comments
 (0)