Closed Solumin closed 7 months ago
Thanks for the excellent reproducible issue, this has been fixed in #593.
Admittedly, this is a really weird case that would probably be solved by making y a private field (https://github.com/jcrist/msgspec/issues/199).
As part of that work I also intend to support field level configuration for eq
/repr
/init
, matching the behavior of dataclasses and attrs. When that's done, you should be able to do something like this to get what you want:
class A(msgspec.Struct):
x: int
y: int = msgspec.field(eq=False)
Thank you for fixing this so quickly!
As part of that work I also intend to support field level configuration for eq/repr/init, matching the behavior of dataclasses and attrs.
Excellent, I think that will be a very helpful feature.
Description
I've encountered unexpected behavior with custom-defined
__eq__
methods:The default implementation of
__ne__
just defers to__eq__
, sox != y
should beFalse
. It seems thatStruct
has its own__ne__
implementation that does not do this.Admittedly, this is a really weird case that would probably be solved by making
y
a private field (#199). I'd also be happy with just updating the docs to state that if you provide a custom__eq__
that you should also define__ne__
.