Skip to content

Mention what argument has both annotation and type argument #1410

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

Merged
merged 3 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.d/1410.change.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion src/attr/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down