You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following is a common pattern in implementations of __cmp__ or __eq__:
sage: search_src("__dict__ == ")
categories/poor_man_map.py:93: return self.__class__ is other.__class__ and self.__dict__ == other.__dict__
combinat/dlx.py:142: return self.__dict__ == other.__dict__
combinat/knutson_tao_puzzles.py:586: return self.__dict__ == other.__dict__
geometry/toric_plotter.py:264: return type(self) is type(other) and self.__dict__ == other.__dict__
misc/misc.py:1611: return self.__class__ == other.__class__ and self.__dict__ == other.__dict__
modules/with_basis/morphism.py:334: return self.__class__ is other.__class__ and parent(self) == parent(other) and self.__dict__ == other.__dict__
modules/with_basis/morphism.py:1474: return self.__class__ is other.__class__ and self.__dict__ == other.__dict__
This fails as soon as self has a @cached_method:
Instances that would be considered equal but have different elements in their cache are not detected as being equal anymore.
A restored pickle contains a PickledMethod which is not considered the same as the CachedMethodCaller(NoArgs) in the original object.
Interestingly, almost all these cases, do not implement __ne__ which makes != not the negation of ==. Also, most do not implement __hash__, or implement it incorrectly,
The instances which use this in their implementations of __cmp__ seem to be limited to doctest/. There, such an implementation should be fine:
The following is a common pattern in implementations of
__cmp__
or__eq__
:This fails as soon as
self
has a@cached_method
:PickledMethod
which is not considered the same as theCachedMethodCaller(NoArgs)
in the original object.Interestingly, almost all these cases, do not implement
__ne__
which makes!=
not the negation of==
. Also, most do not implement__hash__
, or implement it incorrectly,The instances which use this in their implementations of
__cmp__
seem to be limited todoctest/
. There, such an implementation should be fine:Depends on #19820
Depends on #21995
Component: pickling
Issue created by migration from https://trac.sagemath.org/ticket/21894
The text was updated successfully, but these errors were encountered: