-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Sooo, since I just ran into it myself: when I assert over classes, I obviously get an error similar to X(1) != X(2)
. Which once you have more than a handful of attributes becomes unreadable.
I usually use asdict temporarily and just do a assert attr.asdict(x) == attr.asdict(y)
which will give me a nice diff. I know that other people also already did some hacking on this.
Now with attrs classes (and the upcoming dataclasses), it wouldn’t be too hard to give us nice, rich asserts: Once you detect inequality, you “just” have to check for (equal types obviously, and then) x.__attrs_attrs__
, and if it exists pluck out attributes that are used for equality from there and find out which are actually not equal.
And ✨, you can tell the user exactly which attributes failed the equality test. Does that sound interesting for you at all? Now that 3.7 is out, I’m confident people will be interested in such a feature and IIRC, DCs and attrs are implemented similarly so both could/should be implemented at once.